| 146 | } |
| 147 | |
| 148 | bool isDiskOfMMAPFileCorrupted(MemoryFile *file, bool &needReportReadFail) { |
| 149 | uint32_t info; |
| 150 | auto fd = file->getFd(); |
| 151 | auto path = file->getPath().c_str(); |
| 152 | |
| 153 | auto oldPos = lseek(fd, 0, SEEK_CUR); |
| 154 | lseek(fd, 0, SEEK_SET); |
| 155 | auto size = read(fd, &info, sizeof(info)); |
| 156 | auto err = errno; |
| 157 | lseek(fd, oldPos, SEEK_SET); |
| 158 | |
| 159 | if (size <= 0) { |
| 160 | needReportReadFail = true; |
| 161 | MMKVError("fail to read [%s] from fd [%d], errno: %d (%s)", path, fd, err, strerror(err)); |
| 162 | if (err == EDEVERR || err == EILSEQ || err == EINVAL || err == ENXIO) { |
| 163 | MMKVWarning("file fail to read, consider it illegal, delete now: [%s]", path); |
| 164 | return true; |
| 165 | } |
| 166 | } |
| 167 | file->cleanMayflyFD(); |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | } // namespace mmkv |
| 172 |
nothing calls this directly
no test coverage detected