/************************************************* Function: PasswordInit Description: Input: Output: Return: Others: *************************************************/ static void PasswordInit(void) { int i; INT8U CardKey[6]; for(i = 0; i < ICCARD_COUNT; i++) { StorageRead(ADDRESS_PASSWD(i),CardKey,6); memcpy(&mRFIDPwd[i][0], CardKey, 6); } StorageRead(ADDRESS_CHECK,mRFIDCrc,16); }
FileSystemCode_t FsReadFromFile( _In_ FileSystemDescriptor_t* FileSystem, _In_ MfsEntryHandle_t* Handle, _In_ DmaBuffer_t* BufferObject, _In_ size_t Length, _Out_ size_t* BytesAt, _Out_ size_t* BytesRead) { MfsInstance_t* Mfs = (MfsInstance_t*)FileSystem->ExtensionData; MfsEntry_t* Entry = (MfsEntry_t*)Handle->Base.Entry; FileSystemCode_t Result = FsOk; uintptr_t DataPointer = GetBufferDma(BufferObject); uint64_t Position = Handle->Base.Position; size_t BucketSizeBytes = Mfs->SectorsPerBucket * FileSystem->Disk.Descriptor.SectorSize; size_t BytesToRead = Length; TRACE("FsReadFile(Id 0x%x, Position %u, Length %u)", Handle->Base.Id, LODWORD(Handle->Base.Position), Length); *BytesRead = 0; *BytesAt = Handle->Base.Position % FileSystem->Disk.Descriptor.SectorSize; // Sanitize the amount of bytes we want to read, cap it at bytes available if ((Position + BytesToRead) > Entry->Base.Descriptor.Size.QuadPart) { if (Position == Entry->Base.Descriptor.Size.QuadPart) { return FsOk; } BytesToRead = (size_t)(Entry->Base.Descriptor.Size.QuadPart - Position); } // Debug counter values TRACE(" > dma: 0x%x, fpos %u, bytes-total %u, bytes-at %u", DataPointer, LODWORD(Position), BytesToRead, *BytesAt); // Read the current sector, update index to where data starts // Keep reading consecutive after that untill all bytes requested have // been read // Read in a loop to make sure we read all requested bytes while (BytesToRead) { // Calculate which bucket, then the sector offset // Then calculate how many sectors of the bucket we need to read uint64_t Sector = MFS_GETSECTOR(Mfs, Handle->DataBucketPosition); // Start-sector of current bucket uint64_t SectorOffset = Position % FileSystem->Disk.Descriptor.SectorSize; // Byte-offset into the current sector size_t SectorIndex = (size_t)((Position - Handle->BucketByteBoundary) / FileSystem->Disk.Descriptor.SectorSize); // The sector-index into the current bucket size_t SectorsLeft = MFS_GETSECTOR(Mfs, Handle->DataBucketLength) - SectorIndex; // How many sectors are left in this bucket size_t SectorCount; size_t SectorsFitInBuffer; size_t ByteCount; // Calculate the sector index into bucket Sector += SectorIndex; // Calculate how many sectors we should read in SectorCount = DIVUP(BytesToRead, FileSystem->Disk.Descriptor.SectorSize); SectorsFitInBuffer = (GetBufferSize(BufferObject) - *BytesRead) / FileSystem->Disk.Descriptor.SectorSize; if (SectorOffset != 0 && (SectorOffset + BytesToRead > FileSystem->Disk.Descriptor.SectorSize)) { SectorCount++; // Take into account the extra sector we have to read } // Adjust for bucket boundary, and adjust again for buffer size SectorCount = MIN(SectorCount, SectorsLeft); SectorCount = MIN(SectorCount, SectorsFitInBuffer); if (SectorCount == 0) { break; } // Adjust for number of bytes already consumed in the active sector ByteCount = MIN(BytesToRead, (SectorCount * FileSystem->Disk.Descriptor.SectorSize) - SectorOffset); // Ex pos 490 - length 50 // SectorIndex = 0, SectorOffset = 490, SectorCount = 2 - ByteCount = 50 (Capacity 4096) // Ex pos 1109 - length 450 // SectorIndex = 2, SectorOffset = 85, SectorCount = 2 - ByteCount = 450 (Capacity 4096) // Ex pos 490 - length 4000 // SectorIndex = 0, SectorOffset = 490, SectorCount = 8 - ByteCount = 3606 (Capacity 4096) TRACE(" > sector %u (b-start %u, b-index %u), num-sectors %u, sector-byte-offset %u, bytecount %u", LODWORD(Sector), LODWORD(Sector) - SectorIndex, SectorIndex, SectorCount, LODWORD(SectorOffset), ByteCount); if ((GetBufferSize(BufferObject) - *BytesRead) < (SectorCount * FileSystem->Disk.Descriptor.SectorSize)) { WARNING(" > not enough room in buffer for transfer"); break; } // Perform the read (Raw - as we need to pass the datapointer) if (StorageRead(FileSystem->Disk.Driver, FileSystem->Disk.Device, FileSystem->SectorStart + Sector, DataPointer, SectorCount, &SectorCount) != OsSuccess) { ERROR("Failed to read sector"); Result = FsDiskError; break; } // Increase the pointers and decrease with bytes read, take into account // we might not have been able to read all data in one go if ((FileSystem->Disk.Descriptor.SectorSize * SectorCount) < ByteCount) { ByteCount = FileSystem->Disk.Descriptor.SectorSize * SectorCount; } DataPointer += FileSystem->Disk.Descriptor.SectorSize * SectorCount; *BytesRead += ByteCount; Position += ByteCount; BytesToRead -= ByteCount; // Do we need to switch bucket? // We do if the position we have read to equals end of bucket if (Position == (Handle->BucketByteBoundary + (Handle->DataBucketLength * BucketSizeBytes))) { Result = MfsSwitchToNextBucketLink(FileSystem, Handle, BucketSizeBytes); if (Result == FsPathNotFound || Result != FsOk) { if (Result == FsPathNotFound) { Result = FsOk; } break; } } } // if (update_when_accessed) @todo // entry->accessed = now // entry->action_on_close = update TRACE(" > bytes read %u/%u", *BytesRead, Length); return Result; }
//////////////////////////////////////////////////////////////////////// // DumpColumn // //////////////////////////////////////////////////////////////////////// void DumpColumn ( DBBINDING* pBinding, void* pData ) { ASSERT(pBinding && pData); void* p = NULL; BOOL fIsUnicode = TRUE; WCHAR wszBuffer[MAX_QUERY_LEN]; HRESULT hr = S_OK; VARIANT* pvVariant = NULL; IUnknown* pIUnknown = NULL; void* pByRef = NULL; // Pretty print a column. // May have different type of binding. DBSTATUS dwStatus = STATUS_BINDING(*pBinding, pData); DBLENGTH dwLength = LENGTH_BINDING(*pBinding, pData); DBTYPE wType = pBinding->wType; switch(dwStatus) { case DBSTATUS_S_ISNULL: dwLength = 0; break; case DBSTATUS_S_OK: case DBSTATUS_S_TRUNCATED: switch(wType) { case DBTYPE_BSTR: case DBTYPE_WSTR: // We have a string in our buffer, so use it. p = &VALUE_BINDING(*pBinding, pData); dwLength = wcslen((WCHAR*)p); break; case DBTYPE_STR: // We have a string in our buffer, so use it. p = &VALUE_BINDING(*pBinding, pData); dwLength = strlen((CHAR*)p); fIsUnicode = FALSE; break; case DBTYPE_VARIANT: // We have a variant in our buffer, so convert to string. pvVariant = (VARIANT*)&VALUE_BINDING(*pBinding, pData); wType = V_VT(pvVariant); //VariantChangeTypeEx seems to handle most types, TESTC(VariantToString(pvVariant, wszBuffer, MAX_QUERY_LEN, FALSE)); p = wszBuffer; break; case DBTYPE_HCHAPTER: { HCHAPTER hChapter = (HCHAPTER)VALUE_BINDING(*pBinding, pData); swprintf(wszBuffer, L"%lu", hChapter); p = wszBuffer; break; } case DBTYPE_IUNKNOWN: case DBTYPE_IUNKNOWN | DBTYPE_BYREF: { //It's possible that this object supports a storage object //If so, read all the data from the Storage Object and dump it //Otherwise just output the actual ptr static WCHAR s_rgchByteHex[] = L"0123456789ABCDEF"; ULONG cBytesRead = 0; ULONG ulMaxSize = MAX_QUERY_LEN / 2; BYTE* pbBuffer = (BYTE*)PROVIDER_ALLOC(ulMaxSize); WCHAR* pch = wszBuffer; p = wszBuffer; pIUnknown = (IUnknown*)VALUE_BINDING(*pBinding, pData); if(wType & DBTYPE_BYREF) { pByRef = (void*)VALUE_BINDING(*pBinding, pData); pIUnknown = *(IUnknown**)pByRef; } hr = StorageRead(IID_IUnknown, pIUnknown, pbBuffer, ulMaxSize, &cBytesRead); if (hr == S_OK || hr == S_FALSE) { // Convert the byte buffer to string. for (BYTE *pb = pbBuffer; cBytesRead ;cBytesRead--, pb++) { *pch++ = s_rgchByteHex[*pb >> 4]; *pch++ = s_rgchByteHex[*pb & 0x0F]; } *pch = L'\0'; } else { swprintf(wszBuffer, L"%p", pIUnknown); } SAFE_FREE(pbBuffer); break; } default: if(wType & DBTYPE_VECTOR) { DBVECTOR* pVector = (DBVECTOR*)&VALUE_BINDING(*pBinding, pData); hr = VectorToString(pVector, wType, wszBuffer, MAX_QUERY_LEN); p = wszBuffer; } else if(wType & DBTYPE_ARRAY) { SAFEARRAY* pSafeArray = *(SAFEARRAY**)&VALUE_BINDING(*pBinding, pData); hr = SafeArrayToString(pSafeArray, wType, wszBuffer, MAX_QUERY_LEN); p = wszBuffer; } else { p = L"??? Unknown Type ???"; dwLength = 0; } break; } break; default: p = L"??? Unknown Status ???"; dwLength = 0; break; };