size_t FileManagerPosix::numSlots(const block_id block) const { string filename(blockFilename(block)); struct stat file_stat; if (stat(filename.c_str(), &file_stat) == -1) { if (errno != ENOENT) { LOG_WARNING("Failed to retrieve info about file " << filename << " with error: " << strerror(errno)); } return 0; } if ((file_stat.st_size % kSlotSizeBytes) != 0) { throw CorruptPersistentStorage(); } return static_cast<size_t>(file_stat.st_size) / kSlotSizeBytes; }
size_t FileManagerWindows::numSlots(const block_id block) const { const string filename(blockFilename(block)); WIN32_FILE_ATTRIBUTE_DATA file_stat; if (!GetFileAttributesEx(filename.c_str(), GetFileExInfoStandard, &file_stat)) { DWORD error_code = GetLastError(); if (error_code != ERROR_FILE_NOT_FOUND) { LOG(ERROR) << "Failed to retrieve info about file " << filename << " with error_code: " << error_code; } return 0; } uint64_t file_size = (static_cast<uint64_t>(file_stat.nFileSizeHigh) << 32) | file_stat.nFileSizeLow; if ((file_size % kSlotSizeBytes) != 0) { throw CorruptPersistentStorage(); } return static_cast<size_t>(file_size / kSlotSizeBytes); }
size_t FileManagerHdfs::numSlots(const block_id block) const { string filename(blockFilename(block)); hdfsFileInfo *file_info = hdfsGetPathInfo(hdfs_, filename.c_str()); if (file_info == nullptr) { if (errno != ENOENT) { LOG_WARNING("Failed to get size of file " << filename << " with error: " << strerror(errno)); } return 0; } size_t file_size = file_info->mSize; hdfsFreeFileInfo(file_info, 1); if ((file_size % kSlotSizeBytes) != 0) { throw CorruptPersistentStorage(); } return file_size / kSlotSizeBytes; }