void CLogActions::AddLogSimpleLine(const char* szFile, const char* sString, DWORD dwMaxLogSize) { CSmartLock SL(&cs,TRUE); void* pVoid=NULL; CString* pBuffer=NULL; if(aLogBuffer.Lookup(szFile,pVoid)){ pBuffer=(CString*)pVoid; }else{ pBuffer=ReadFromDisk(szFile); } if(!pBuffer){ return; } DWORD dwMaxSize=((dwMaxLogSize==0?objSettings.dwMaxLogFileSize:dwMaxLogSize)*1024); CString sNewContent=sString; sNewContent+=*pBuffer; if(strlen(sNewContent)>dwMaxSize){ long lCutPos=sNewContent.Find(HTMLCUTLINE3,dwMaxSize); if(lCutPos!=-1){ sNewContent=sNewContent.Left(lCutPos); } } *pBuffer=sNewContent; return; }
LPVOID CSoundData::Get() { ++m_iRefCount; m_dwAccessTime = ELTimer_GetMSec(); if (!m_data) ReadFromDisk(); if (m_flag & FLAG_DATA_SIZE) return ((S32 *) m_data + 1); else return (m_data); }
//***************************************************************************** // Caller wants a pointer to a chunk of the file. This function will make sure // that the memory for that chunk has been committed and will load from the // file if required. This algorithm attempts to load no more data from disk // than is necessary. It walks the required pages from lowest to highest, // and for each block of unloaded pages, the memory is committed and the data // is read from disk. If all pages are unloaded, all of them are loaded at // once to speed throughput from disk. //***************************************************************************** HRESULT StgIO::GetPtrForMem( // Return code. ULONG cbStart, // Where to start getting memory. ULONG cbSize, // How much data. void *&ptr) // Return pointer to memory here. { int iFirst, iLast; // First and last page required. ULONG iOffset, iSize; // For committing ranges of memory. int i, j; // Loop control. HRESULT hr; // We need either memory (mmf or user supplied) or a backing store to // return a pointer. Call Read if you don't have these. if (!IsBackingStore() && m_pData == 0) return (PostError(BadError(E_UNEXPECTED))); // Validate the caller isn't asking for a data value out of range. if (!(ClrSafeInt<ULONG>::addition(cbStart, cbSize, iOffset) && (iOffset <= m_cbData))) return (PostError(E_INVALIDARG)); // This code will check for pages that need to be paged from disk in // order for us to return a pointer to that memory. if (IsBackingStore()) { // Backing store is bogus when in rewrite mode. if (m_bRewrite) return (PostError(BadError(E_UNEXPECTED))); // Must have the page map to continue. _ASSERTE(m_rgPageMap && m_iPageSize && m_pData); // Figure out the first and last page that are required for commit. iFirst = cbStart / m_iPageSize; iLast = (cbStart + cbSize - 1) / m_iPageSize; // Avoid confusion. ptr = 0; // Do a smart load of every page required. Do not reload pages that have // already been brought in from disk. //<REVISIT_TODO>@FUTURE: add an optimization so that when all pages have been faulted, we no // longer to a page by page search.</REVISIT_TODO> for (i=iFirst; i<=iLast; ) { // Find the first page that hasn't already been loaded. while (GetBit(m_rgPageMap, i) && i<=iLast) ++i; if (i > iLast) break; // Offset for first thing to load. iOffset = i * m_iPageSize; iSize = 0; // See how many in a row have not been loaded. for (j=i; i<=iLast && !GetBit(m_rgPageMap, i); i++) { // Safe: iSize += m_iPageSize; if (!(ClrSafeInt<ULONG>::addition(iSize, m_iPageSize, iSize))) { return PostError(E_INVALIDARG); } } // First commit the memory for this part of the file. if (::ClrVirtualAlloc((void *) ((DWORD_PTR) m_pData + iOffset), iSize, MEM_COMMIT, PAGE_READWRITE) == 0) return (PostError(OutOfMemory())); // Now load that portion of the file from disk. if (FAILED(hr = Seek(iOffset, FILE_BEGIN)) || FAILED(hr = ReadFromDisk((void *) ((DWORD_PTR) m_pData + iOffset), iSize, 0))) { return (hr); } // Change the memory to read only to avoid any modifications. Any faults // that occur indicate a bug whereby the engine is trying to write to // protected memory. _ASSERTE(::ClrVirtualAlloc((void *) ((DWORD_PTR) m_pData + iOffset), iSize, MEM_COMMIT, PAGE_READONLY) != 0); // Record each new loaded page. for (; j<i; j++) SetBit(m_rgPageMap, j, true); } // Everything was brought into memory, so now return pointer to caller. ptr = (void *) ((DWORD_PTR) m_pData + cbStart); } // Memory version or memory mapped file work the same way. else if (IsMemoryMapped() || (m_iType == STGIO_MEM) || (m_iType == STGIO_SHAREDMEM) || (m_iType == STGIO_HFILEMEM)) { if (!(cbStart <= m_cbData)) return (PostError(E_INVALIDARG)); ptr = (void *) ((DWORD_PTR) m_pData + cbStart); } // What's left?! Add some defense. else { _ASSERTE(0); ptr = 0; return (PostError(BadError(E_UNEXPECTED))); } return (S_OK); }
//***************************************************************************** // Read data from the storage source. This will handle all types of backing // storage from mmf, streams, and file handles. No read ahead or MRU // caching is done. //***************************************************************************** HRESULT StgIO::Read( // Return code. void *pbBuff, // Write buffer here. ULONG cbBuff, // How much to read. ULONG *pcbRead) // How much read. { ULONG cbCopy; // For boundary checks. void *pbData; // Data buffer for mem read. HRESULT hr = S_OK; // Validate arguments, don't call if you don't need to. _ASSERTE(pbBuff != 0); _ASSERTE(cbBuff > 0); // Get the data based on type. switch (m_iType) { // For data on file, there are two possiblities: // (1) We have an in memory backing store we should use, or // (2) We just need to read from the file. case STGIO_HFILE: case STGIO_HMODULE: { _ASSERTE((m_hFile != INVALID_HANDLE_VALUE) || (m_hModule != NULL)); // Backing store does its own paging. if (IsBackingStore() || IsMemoryMapped()) { // Force the data into memory. if (FAILED(hr = GetPtrForMem(GetCurrentOffset(), cbBuff, pbData))) goto ErrExit; // Copy it back for the user and save the size. memcpy(pbBuff, pbData, cbBuff); if (pcbRead) *pcbRead = cbBuff; } // If there is no backing store, this is just a read operation. else { _ASSERTE((m_iType == STGIO_HFILE) && (m_hFile != INVALID_HANDLE_VALUE)); _ASSERTE(m_hModule == NULL); ULONG cbTemp = 0; if (!pcbRead) pcbRead = &cbTemp; hr = ReadFromDisk(pbBuff, cbBuff, pcbRead); m_cbOffset += *pcbRead; } } break; // Data in a stream is always just read. case STGIO_STREAM: { _ASSERTE((IStream *) m_pIStream); if (!pcbRead) pcbRead = &cbCopy; *pcbRead = 0; hr = m_pIStream->Read(pbBuff, cbBuff, pcbRead); if (SUCCEEDED(hr)) m_cbOffset += *pcbRead; } break; // Simply copy the data from our data. case STGIO_MEM: case STGIO_SHAREDMEM: case STGIO_HFILEMEM: { _ASSERTE(m_pData && m_cbData); // Check for read past end of buffer and adjust. if (GetCurrentOffset() + cbBuff > m_cbData) cbCopy = m_cbData - GetCurrentOffset(); else cbCopy = cbBuff; // Copy the data into the callers buffer. memcpy(pbBuff, (void *) ((DWORD_PTR)m_pData + GetCurrentOffset()), cbCopy); if (pcbRead) *pcbRead = cbCopy; // Save a logical offset. m_cbOffset += cbCopy; } break; case STGIO_NODATA: default: _ASSERTE(0); break; } ErrExit: return (hr); }
/** Reread file information */ void SCXFileInfo::Refresh() { ReadFromDisk(); }
Bookkeeper::Bookkeeper() { ClearAll(); ReadFromDisk(); }