MCPcopy Create free account
hub / github.com/Tencent/MMKV / isDiskOfMMAPFileCorrupted

Function isDiskOfMMAPFileCorrupted

Core/MemoryFile_Win32.cpp:626–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

624}
625
626bool isDiskOfMMAPFileCorrupted(MemoryFile *file, bool &needReportReadFail) {
627 // make sure the file is valid
628 __try {
629 auto filesize = file->getFileSize();
630 volatile uint8_t* ptr = (uint8_t*) file->getMemory();
631 // check the head of every page
632 for (size_t index = 0; index < filesize; index += DEFAULT_MMAP_SIZE) {
633 volatile uint8_t byte = ptr[index];
634 MMKVDebug("%zu byte of the file: 0x%x", index, byte);
635 }
636 // check the very last byte of the file
637 if (filesize > 1) {
638 volatile uint8_t byte = ptr[filesize - 1];
639 MMKVDebug("%zu byte of the file: 0x%x", filesize - 1, byte);
640 }
641 }
642 __except ((GetExceptionCode() == EXCEPTION_IN_PAGE_ERROR || GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
643 ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
644 needReportReadFail = true;
645 DWORD errorCode = GetExceptionCode();
646 MMKVError("fail to mmap [%s], %d", file->getUTF8Path().c_str(), errorCode);
647 return true;
648 }
649 return false;
650}
651
652bool deleteFile(const MMKVPath_t &path) {
653 if (!DeleteFile(path.c_str())) {

Callers

nothing calls this directly

Calls 2

getFileSizeMethod · 0.80
getMemoryMethod · 0.80

Tested by

no test coverage detected