static NTFS_CACHE_ENTRY* _NTFS_cache_getPage(NTFS_CACHE *cache,sec_t sector) { unsigned int i; NTFS_CACHE_ENTRY* cacheEntries = cache->cacheEntries; unsigned int numberOfPages = cache->numberOfPages; unsigned int sectorsPerPage = cache->sectorsPerPage; bool foundFree = false; unsigned int oldUsed = 0; unsigned int oldAccess = UINT_MAX; // if sector is before of start of partition return with error if(sector < cache->startOfPartition) return NULL; for(i=0;i<numberOfPages;i++) { if(sector>=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) { cacheEntries[i].last_access = accessTime(); return &(cacheEntries[i]); } if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_access<oldAccess)) { if(cacheEntries[i].sector==CACHE_FREE) foundFree = true; oldUsed = i; oldAccess = cacheEntries[i].last_access; } } if(foundFree==false && cacheEntries[oldUsed].dirty==true) { // start of partition correction offset sec_t salign = (cacheEntries[oldUsed].sector < cache->startOfPartition) ? cache->startOfPartition - cacheEntries[oldUsed].sector : 0; if(!cache->disc->writeSectors(cacheEntries[oldUsed].sector + salign, cacheEntries[oldUsed].count - salign, cacheEntries[oldUsed].cache + salign * cache->sectorSize)) return NULL; cacheEntries[oldUsed].dirty = false; } sector = cache->startOfPartition + ((sector - cache->startOfPartition)/sectorsPerPage)*sectorsPerPage; // align base sector to page size sec_t next_page = sector + sectorsPerPage; if(next_page > cache->endOfPartition) next_page = cache->endOfPartition; if(!cache->disc->readSectors(sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL; cacheEntries[oldUsed].dirty = false; cacheEntries[oldUsed].sector = sector; cacheEntries[oldUsed].count = next_page-sector; cacheEntries[oldUsed].last_access = accessTime(); return &(cacheEntries[oldUsed]); }
CACHE_ENTRY* _FAT_cache_getPage(CACHE *cache,sec_t sector) { unsigned int i; CACHE_ENTRY* cacheEntries = cache->cacheEntries; unsigned int numberOfPages = cache->numberOfPages; unsigned int sectorsPerPage = cache->sectorsPerPage; bool foundFree = false; unsigned int oldUsed = 0; unsigned int oldAccess = UINT_MAX; for(i=0;i<numberOfPages;i++) { if(sector>=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) { cacheEntries[i].last_access = accessTime(); return &(cacheEntries[i]); } if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_access<oldAccess)) { if(cacheEntries[i].sector==CACHE_FREE) foundFree = true; oldUsed = i; oldAccess = cacheEntries[i].last_access; } } if(foundFree==false && cacheEntries[oldUsed].dirty==true) { if(!_FAT_disc_writeSectors(cache->disc,cacheEntries[oldUsed].sector,cacheEntries[oldUsed].count,cacheEntries[oldUsed].cache)) return NULL; cacheEntries[oldUsed].dirty = false; } sector = (sector/sectorsPerPage)*sectorsPerPage; // align base sector to page size sec_t next_page = sector + sectorsPerPage; if(next_page > cache->endOfPartition) next_page = cache->endOfPartition; if(!_FAT_disc_readSectors(cache->disc,sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL; cacheEntries[oldUsed].sector = sector; cacheEntries[oldUsed].count = next_page-sector; cacheEntries[oldUsed].last_access = accessTime(); return &(cacheEntries[oldUsed]); }
void C_Log::writeHeader() { char logTypeStr = accessLogTypeStr(); struct tm time = accessTime(); char dateStr[11]; strftime(dateStr, sizeof(dateStr), "%Y-%m-%d", &time); char timeStr[9]; strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &time); C_Log::_buffer << "[" << logTypeStr << "]" << "[" << dateStr << " " << timeStr << "] "; }
bool _NTFS_cache_writeSectors (NTFS_CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer) { sec_t sec; sec_t secs_to_write; NTFS_CACHE_ENTRY *entry, *entry2; const uint8_t *src = buffer; // if sector is before of start of partition return with error if(sector < cache->startOfPartition) return false; while(numSectors>0) { entry = _NTFS_cache_findPage(cache,sector/*,numSectors*/); if(entry!=NULL){ entry->last_access = accessTime(); sec = sector - entry->sector; secs_to_write = entry->count - sec; if(secs_to_write>numSectors) secs_to_write = numSectors; memcpy(entry->cache + (sec*cache->sectorSize),src,(secs_to_write*cache->sectorSize)); src += (secs_to_write*cache->sectorSize); sector += secs_to_write; numSectors -= secs_to_write; entry->dirty = true; } else { // old //cache->disc->writeSectors(sector,numSectors,src); //numSectors=0; // limit to sectorPerPage size to align sector secs_to_write = cache->sectorsPerPage - ((sector - cache->startOfPartition) % cache->sectorsPerPage); sec = 0; if(secs_to_write < numSectors) { while(1) { entry2 = _NTFS_cache_findPage(cache,sector + secs_to_write); if(entry2!=NULL) {secs_to_write-= sec; break;} // limit with numSectors to break the loop if(secs_to_write > numSectors) break; sec = cache->sectorsPerPage; secs_to_write+= sec; } } // limit with numSectors if(secs_to_write > numSectors) secs_to_write = numSectors; // limit to the end of partition if((sector + secs_to_write) > cache->endOfPartition) secs_to_write -= (sector + secs_to_write) - cache->endOfPartition; // start of partition correction offset sec_t salign = (sector < cache->startOfPartition) ? cache->startOfPartition - sector : 0; if(!cache->disc->writeSectors(sector + salign, secs_to_write - salign,src + salign * cache->sectorSize)) return false; src += (secs_to_write*cache->sectorSize); sector += secs_to_write; numSectors -= secs_to_write; } } return true; }
gbool GUrlCache::GetCacheStats(const char *directory, time_t &oldest,DWORD &spaceInUse, int &filesInUse) { CFileFind finder; CString dir = directory; // add separator int l = dir.GetLength(); if (l == 0) return FALSE; if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\'; dir += "*.*"; CString path; CTime creationTime((time_t)0); CTime accessTime((time_t)0); CTime writeTime((time_t)0); // setup the find structure BOOL bWorking = finder.FindFile(dir); while (bWorking) { // for all entrys if (stop) break; bWorking = finder.FindNextFile(); path = finder.GetFilePath(); creationTime = (time_t)0; accessTime = (time_t)0; writeTime = (time_t)0; BOOL ret=finder.GetCreationTime(creationTime); finder.GetLastAccessTime(accessTime); finder.GetLastWriteTime(writeTime); time_t t = creationTime.GetTime(); if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime()); if (finder.IsDots( )) { // ignore . .. } else if (finder.IsDirectory( )) { // recursively step down GetCacheStats(path,oldest,spaceInUse,filesInUse); } else { DWORD length = finder.GetLength(); TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length); oldest = min(oldest,t); filesInUse++; spaceInUse += length; } } finder.Close(); return TRUE; }
// recursively remove a file branch gbool GUrlCache::RemoveFiles(const char *directory,time_t olderThan) { CFileFind finder; CString dir = directory; // add separator int l = dir.GetLength(); if (l == 0) return FALSE; if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\'; dir += "*.*"; CString path; CTime creationTime((time_t)0); CTime accessTime((time_t)0); CTime writeTime((time_t)0); // setup the find structure BOOL bWorking = finder.FindFile(dir); LONGLONG fileSum=0; while (bWorking) { // for all entrys if (stop) break; bWorking = finder.FindNextFile(); path = finder.GetFilePath(); creationTime = (time_t)0; accessTime = (time_t)0; writeTime = (time_t)0; BOOL ret=finder.GetCreationTime(creationTime); finder.GetLastAccessTime(accessTime); finder.GetLastWriteTime(writeTime); time_t t = creationTime.GetTime(); // if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime()); if (finder.IsDots( )) { // ignore . .. } else if (finder.IsDirectory( )) { // recursively step down RemoveFiles(path,olderThan); RemoveDirectory(path); } else { DWORD length = finder.GetLength(); TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length); if (olderThan >0 ) { if (t < olderThan) { if (RemoveFile(path)) fileSum += length; } } else { if (RemoveFile(path)) fileSum += length; } } } finder.Close(); TRACE("%ld bytes deleted \n",(long) fileSum); return TRUE; }
// add files to list gbool GFileSorter::AddFiles(const char *directory,time_t &maxFileTime,BOOL &stop) { CFileFind finder; CString dir = directory; // add separator int l = dir.GetLength(); if (l == 0) return FALSE; if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\'; dir += "*.*"; CString path; CTime creationTime((time_t)0); CTime accessTime((time_t)0); CTime writeTime((time_t)0); // setup the find structure BOOL bWorking = finder.FindFile(dir); while (bWorking) { // for all entrys if (stop) break; bWorking = finder.FindNextFile(); path = finder.GetFilePath(); creationTime = (time_t)0; accessTime = (time_t)0; writeTime = (time_t)0; BOOL ret=finder.GetCreationTime(creationTime); finder.GetLastAccessTime(accessTime); finder.GetLastWriteTime(writeTime); time_t t = creationTime.GetTime(); if (writeTime.GetTime()>0) t = max(t,writeTime.GetTime()); // HG wg Kristof if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime()); if (finder.IsDots( )) { // ignore . .. } else if (finder.IsDirectory( )) { // recursively step down t=0; // we want to delete empty directories new 20.10.98 AddFiles(path,t,stop); DWORD length = 0; // to do get date of latest TRACE("D %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length); // time is the max of the child time +1 GFSortEntry *e = new GFSortEntry(path,t+1,length,gtrue); if (!e) break; if (!Add(e)) break; if (t>maxFileTime) maxFileTime = t; } else { DWORD length = finder.GetLength(); // get length 64 fileSum += length; TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length); GFSortEntry *e = new GFSortEntry(path,t,length); if (t>maxFileTime) maxFileTime = t; if (!e) break; if (!Add(e)) break; } } finder.Close(); //TRACE("%ld bytes \n",(long)fileSum); return TRUE; }