我正在编写一个小型实用程序来解析Windows上的xfs文件系统。 对于小于5GB的小型图像,我的实用程序可以正常工作:我能够列出所有文件和目录。 但是当我尝试解析大于30GB的xfs图像时,它会给出错误的结果。 我使用_fseeki64和_ftelli64进行搜索,并使用fread读取特定块。 我注意到其中一个问题是_fseeki64无法正常工作。 下面是我的搜索函数,它会搜索特定的组号和块号。
int FileSystemReadXFS::SeekToGroupBlock(uint16_t grpNum, uint64_t blockNum)
{
int error = -1;
//Seek to beginning
if(_fseeki64(m_fileSystemInfo.fp, (__int64)0, SEEK_SET) != 0)
{
PRINT_SEEK_ERROR;
goto BAILOUT;
}
__int64 currPtr = 0;
//Seek to destination group
if(grpNum > 0)
{
if(_fseeki64(m_fileSystemInfo.fp, (__int64)(grpNum*m_fileSystemInfo.SizeOfBlockGroup*m_fileSystemInfo.BlockSize), SEEK_SET))
{
PRINT_SEEK_ERROR;
goto BAILOUT;
}
currPtr = _ftelli64(m_fileSystemInfo.fp);
}
//Seek to destination block in group
if(blockNum > 0)
{
if(_fseeki64(m_fileSystemInfo.fp, (__int64)(blockNum*m_fileSystemInfo.BlockSize), SEEK_CUR))
{
PRINT_SEEK_ERROR;
goto BAILOUT;
}
currPtr = _ftelli64(m_fileSystemInfo.fp);
}
error = 0;
BAILOUT:
return error;
}
然而,上述函数将我带到了错误的位置。例如,当我想要查找组号为2,并且m_fileSystemInfo.SizeOfBlockGroup = 2043982且m_fileSystemInfo.BlockSize = 4096时。
我期望的currPrt = 2043982 * 4096 * 2 = 16744300544(0x3E609C000),但_ftelli64返回的是(0xE609C000)。请建议可能出了什么问题。此外,请建议在C++中处理Windows上的大文件的最佳方法。
更新:
我发现seekOffset被限制为8154365952(0x1e609c000),而不是实际值16744300544(0x3e609c000),即使我使用__int64。
所以,
__int64 seekOff = (__int64)(grpNum * m_fileSystemInfo.SizeOfBlockGroup * m_fileSystemInfo.BlockSize) = 2 * 2043982 * 4096
给出的结果是8154365952,而不是16744300544。
我不确定原因是什么,因为所有变量都是__int64类型。