FAT drive root entry. More...
#include <fatfs.h>
Public Member Functions | |
FATDrive (LPCTSTR path) | |
~FATDrive () | |
bool | read_sector (DWORD sec, Buffer *buf, int len) |
DWORD | read_FAT (DWORD Clus, bool &ok) |
void | small_cache () |
void | reset_cache () |
bool | read_cache (DWORD sec, Buffer **bufptr) |
int | get_cache_buffer () |
Public Attributes | |
HANDLE | _hDrive |
BootSector | _boot_sector |
int | _bufl |
int | _bufents |
int | _SClus |
Cache * | _FATCache |
int | _CacheCount |
DWORD * | _CacheSec |
int * | _CacheCnt |
bool * | _CacheDty |
int | _Caches |
bool | _cache_empty |
int | _read_ahead |
FAT drive root entry.
Definition at line 225 of file fatfs.h.
FATDrive::FATDrive | ( | LPCTSTR | path ) |
Definition at line 410 of file fatfs.cpp.
References _boot_sector, _bufents, _bufl, _CacheCnt, _CacheCount, _CacheDty, _Caches, _CacheSec, _FATCache, _hDrive, _SClus, BootSector::BytesPerSector, read_sector(), and small_cache().
: FATDirectory(*this, TEXT("\\")) { _bufl = 0; _bufents = 0; _SClus = 0; _FATCache = NULL; _CacheCount = 0; _CacheSec = NULL; _CacheCnt = NULL; _CacheDty = NULL; _Caches = 0; _hDrive = CreateFile(path, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); if (_hDrive != INVALID_HANDLE_VALUE) { _boot_sector.BytesPerSector = 512; if (read_sector(0, (Buffer*)&_boot_sector, 1)) { _bufl = _boot_sector.BytesPerSector; _SClus = _boot_sector.SectorsPerCluster; _bufents = _bufl / sizeof(union DEntry); } small_cache(); } }
FATDrive::~FATDrive | ( | ) |
int FATDrive::get_cache_buffer | ( | ) |
Definition at line 603 of file fatfs.cpp.
References _cache_empty, _CacheCnt, _Caches, and _CacheSec.
Referenced by read_cache().
{ int i, j, minCnt; for(i=0; i<_Caches; i++) if (_CacheSec[i]) break; _cache_empty = i==_Caches? true: false; for(i=0; _CacheSec[i] && i<_Caches; ) ++i; if (i < _Caches) j = i; else { minCnt = 0; // search for least used buffer for(j=i=0; i<_Caches; i++) if (minCnt < _CacheCnt[i]) { minCnt = _CacheCnt[i]; j = i; } /**@todo enable write back if (CacheDty[j]) // Dirty-Flag gesetzt? if (writesec(_CacheSec[j], (Buffer*) &_FATCache[j], 1)) FPara = _CacheSec[j], Frag(SecWriteErr); */ } return j; }
bool FATDrive::read_cache | ( | DWORD | sec, |
Buffer ** | bufptr | ||
) |
Definition at line 555 of file fatfs.cpp.
References _boot_sector, _cache_empty, _CacheCnt, _CacheCount, _CacheDty, _Caches, _CacheSec, _FATCache, _read_ahead, BufLen, BootSector::BytesPerSector, get_cache_buffer(), BootSector::NumberFATs, read_sector(), and BootSector::SectorsPerFAT.
Referenced by read_FAT().
{ int i, C, anz; if (_boot_sector.BytesPerSector != BufLen) // no standard sector size? return read_sector(sec, *bufptr=(Buffer*)&_FATCache[0], 1); _CacheCount++; for(i=0; _CacheSec[i]!=sec && i<_Caches; ) ++i; if (i < _Caches) { *bufptr = (Buffer*) &_FATCache[i]; // FAT-Sektor schon gepuffert _CacheCnt[i]++; return true; } i = get_cache_buffer(); if (_cache_empty) // von get_cache_buffer() gesetzt { C = _CacheCount-1; anz = _boot_sector.SectorsPerFAT*_boot_sector.NumberFATs - sec; if (anz > _read_ahead) anz = _read_ahead; for(i=0; i<anz; i++) { _CacheSec[i] = sec++; _CacheCnt[i] = C; _CacheDty[i] = 0; } _CacheCnt[0] = _CacheCount; return read_sector(_CacheSec[0], *bufptr=(Buffer*) &_FATCache[0], anz); } else { _CacheDty[i] = 0; _CacheCnt[i] = _CacheCount; return read_sector(_CacheSec[i]=sec, *bufptr=(Buffer*) &_FATCache[i], 1); } }
DWORD FATDrive::read_FAT | ( | DWORD | Clus, |
bool & | ok | ||
) |
Definition at line 499 of file fatfs.cpp.
References _boot_sector, BootSector::BytesPerSector, Buffer::dat, dpeek, read_cache(), BootSector::ReservedSectors, BootSector::Sectors16, BootSector::Sectors32, BootSector::SectorsPerCluster, and wpeek.
Referenced by FATDirectory::read_dir().
{ DWORD nClus; Buffer* FATBuf; DWORD nclus = (_boot_sector.Sectors32? _boot_sector.Sectors32: _boot_sector.Sectors16) / _boot_sector.SectorsPerCluster; ///@todo cache result if (cluster > nclus) { ok = false; return (DWORD)-1; } if (nclus >= 65536) { // FAT32 DWORD FATsec = cluster / (_boot_sector.BytesPerSector/4); DWORD z = (cluster - _boot_sector.BytesPerSector/4 * FATsec)*4; FATsec += _boot_sector.ReservedSectors; if (!read_cache(FATsec, &FATBuf)) ok = false; nClus = dpeek(&FATBuf->dat[z]); } else if (nclus >= 4096) { // 16 Bit-FAT DWORD FATsec = cluster / (_boot_sector.BytesPerSector/2); DWORD z = (cluster - _boot_sector.BytesPerSector/2 * FATsec)*2; FATsec += _boot_sector.ReservedSectors; if (!read_cache(FATsec, &FATBuf)) ok = false; nClus = wpeek(&FATBuf->dat[z]); if (nClus >= 0xfff0) nClus |= 0x0fff0000; } else { // 12 Bit-FAT DWORD FATsec = cluster*3 / (_boot_sector.BytesPerSector*2); DWORD z = (cluster*3 - _boot_sector.BytesPerSector*2*FATsec)/2; FATsec += _boot_sector.ReservedSectors; if (!read_cache(FATsec,&FATBuf)) ok = false; BYTE a = FATBuf->dat[z++]; if (z >= _boot_sector.BytesPerSector) if (!read_cache(FATsec+1,&FATBuf)) ok = false; z = 0; BYTE b = FATBuf->dat[z]; if (cluster & 1) nClus = (a>>4) | (b<<4); else nClus = a | ((b & 0xf)<<8); if (nClus >= 0xff0) nClus |= 0x0ffff000; } return nClus; }
bool FATDrive::read_sector | ( | DWORD | sec, |
Buffer * | buf, | ||
int | len | ||
) |
Definition at line 484 of file fatfs.cpp.
References _boot_sector, FATDirectory::_drive, _hDrive, and BootSector::BytesPerSector.
Referenced by FATDrive(), read_cache(), and FATDirectory::read_dir().
{ sec += 63; //@@ jump to first partition if (SetFilePointer(_hDrive, sec*_drive._boot_sector.BytesPerSector, 0, 0) == INVALID_SET_FILE_POINTER) return false; DWORD read; if (!ReadFile(_hDrive, buf, len*_drive._boot_sector.BytesPerSector, &read, 0)) return false; return true; }
void FATDrive::reset_cache | ( | ) |
Definition at line 464 of file fatfs.cpp.
References _CacheCnt, _CacheDty, _Caches, _CacheSec, and _read_ahead.
Referenced by small_cache().
{ int i; if (!_CacheSec) { _CacheSec = (DWORD*) malloc(_Caches * sizeof(DWORD)); _CacheCnt = (int*) malloc(_Caches * sizeof(int)); _CacheDty = (bool*) malloc(_Caches * sizeof(bool)); } else { _CacheSec = (DWORD*) realloc(_CacheSec, _Caches * sizeof(DWORD)); _CacheCnt = (int*) realloc(_CacheCnt, _Caches * sizeof(int)); _CacheDty = (bool*) realloc(_CacheDty, _Caches * sizeof(bool)); } for(i=0; i<_Caches; i++) _CacheSec[i] = 0; _read_ahead = (_Caches+1) / 2; }
void FATDrive::small_cache | ( | ) |
Definition at line 447 of file fatfs.cpp.
References _bufl, _CacheCnt, _CacheDty, _Caches, _CacheSec, FATDirectory::_drive, _FATCache, CACHE_SIZE_LOW, and reset_cache().
Referenced by FATDrive().
{ if (_FATCache) free(_FATCache); if (_CacheSec) { free(_CacheSec), _CacheSec = NULL; free(_CacheCnt); free(_CacheDty); } _Caches = CACHE_SIZE_LOW; _FATCache = (struct Cache *) malloc((_Caches+1) * _drive._bufl); reset_cache(); }
Definition at line 238 of file fatfs.h.
Referenced by FATDrive(), read_cache(), FATDirectory::read_dir(), read_FAT(), and read_sector().
Definition at line 240 of file fatfs.h.
Referenced by FATDrive(), and FATDirectory::read_dir().
int FATDrive::_bufl |
Definition at line 239 of file fatfs.h.
Referenced by FATDrive(), FATDirectory::read_dir(), and small_cache().
Definition at line 250 of file fatfs.h.
Referenced by get_cache_buffer(), and read_cache().
int* FATDrive::_CacheCnt |
Definition at line 247 of file fatfs.h.
Referenced by FATDrive(), get_cache_buffer(), read_cache(), reset_cache(), and small_cache().
Definition at line 245 of file fatfs.h.
Referenced by FATDrive(), and read_cache().
bool* FATDrive::_CacheDty |
Definition at line 248 of file fatfs.h.
Referenced by FATDrive(), read_cache(), reset_cache(), and small_cache().
Definition at line 249 of file fatfs.h.
Referenced by FATDrive(), get_cache_buffer(), read_cache(), reset_cache(), and small_cache().
DWORD* FATDrive::_CacheSec |
Definition at line 246 of file fatfs.h.
Referenced by FATDrive(), get_cache_buffer(), read_cache(), reset_cache(), and small_cache().
Definition at line 244 of file fatfs.h.
Referenced by FATDrive(), read_cache(), and small_cache().
HANDLE FATDrive::_hDrive |
Definition at line 237 of file fatfs.h.
Referenced by FATDrive(), FileChildWindow::FileChildWindow(), read_sector(), and ~FATDrive().
Definition at line 251 of file fatfs.h.
Referenced by read_cache(), and reset_cache().
int FATDrive::_SClus |
Definition at line 241 of file fatfs.h.
Referenced by FATDrive(), and FATDirectory::read_dir().
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |