打开文件的时候,一直困在循环里面出不来,下面第二个程序 这个一直不能通过,while(!flag && (Cur_Clust=FAT32_GetNextCluster(Cur_Clust))!=0x0fffffff);。被这句话卡着了获取的下一个簇的簇号一直是0. pArg->FirstFATSector有数据
求高手指点一二。
/***********************************************************************
- 功能描述:获得下一个簇的簇号
- 隶属模块:znFAT文件系统模块
- 函数属性:内部
- 参数说明:LastCluster:基准簇号
- 返回说明:LastClutster的下一簇的簇号
- 注:获得下一簇的簇号,就是凭借FAT表中所记录的簇链关系来实现的
***********************************************************************/
UINT32 FAT32_GetNextCluster(UINT32 LastCluster)
{
unsigned long temp;
struct FAT32_FAT *pFAT;
struct FAT32_FAT_Item *pFAT_Item;
temp=((LastCluster/128)+pArg->FirstFATSector);
FAT32_ReadSector(temp,FAT32_Buffer);
pFAT=(struct FAT32_FAT *)FAT32_Buffer;
pFAT_Item=&((pFAT->Items)[LastCluster%128]);
return LE2BE((UINT8 *)pFAT_Item,4);
}
UINT8 FAT32_Open_File(struct FileInfoStruct *pfi,INT8 *filepath,unsigned long item)
{
UINT32 Cur_Clust,sec_temp,iSec,iFile,iItem=0;
UINT8 flag=0,index=0,i=0;
struct direntry *pFile;
INT8 temp_file_name[13];
while(filepath[i]!=0)
{
if(filepath[i]=='\\') index=i;
i++;
}
if(Cur_Clust=FAT32_Enter_Dir(filepath))
{
Str2Up(temp_dir_name);
do
{
sec_temp=SOC(Cur_Clust);
for(iSec=sec_temp;iSec<sec_temp+pArg->SectorsPerClust;iSec++)
{
FAT32_ReadSector(iSec,FAT32_Buffer);
for(iFile=0;iFile<pArg->BytesPerSector;iFile+=sizeof(struct direntry))
{
pFile=((struct direntry *)(FAT32_Buffer+iFile));
FAT32_toFileName(pFile->deName,temp_file_name);
if(FilenameMatch(temp_dir_name,temp_file_name) && pFile->deName[0]!=0xe5 && pFile->deAttributes&0x20) //匹配文件名
{
if(item==iItem)
{
flag=1;
Cur_Clust=LE2BE(pFile->deLowCluster,2)+LE2BE(pFile->deHighClust,2)*65536;
pfi->FileSize=LE2BE(pFile->deFileSize,4);
strcpy(pfi->FileName,temp_file_name);
pfi->FileStartCluster=LE2BE(pFile->deLowCluster,2)+LE2BE(pFile->deHighClust,2)*65536;
pfi->FileCurCluster=pfi->FileStartCluster;
pfi->FileCurSector=SOC(pfi->FileStartCluster);
pfi->FileCurPos=0;
pfi->FileCurOffset=0;
pfi->Rec_Sec=iSec;
pfi->nRec=iFile;
pfi->FileAttr=pFile->deAttributes;
sec_temp=LE2BE(pFile->deCTime,2);
(pfi->FileCreateTime).sec=(sec_temp&0x001f)*2;
(pfi->FileCreateTime).min=((sec_temp>>5)&0x003f);
(pfi->FileCreateTime).hour=((sec_temp>>11)&0x001f);
sec_temp=LE2BE(pFile->deCDate,2);
(pfi->FileCreateDate).day=((sec_temp)&0x001f);
(pfi->FileCreateDate).month=((sec_temp>>5)&0x000f);
(pfi->FileCreateDate).year=((sec_temp>>9)&0x007f)+1980;
sec_temp=LE2BE(pFile->deMTime,2);
(pfi->FileMTime).sec=(sec_temp&0x001f)*2;
(pfi->FileMTime).min=((sec_temp>>5)&0x003f);
(pfi->FileMTime).hour=((sec_temp>>11)&0x001f);
sec_temp=LE2BE(pFile->deMDate,2);
(pfi->FileMDate).day=((sec_temp)&0x001f);
(pfi->FileMDate).month=((sec_temp>>5)&0x000f);
(pfi->FileMDate).year=((sec_temp>>9)&0x007f)+1980;
sec_temp=LE2BE(pFile->deADate,2);
(pfi->FileADate).day=((sec_temp)&0x001f);
(pfi->FileADate).month=((sec_temp>>5)&0x000f);
(pfi->FileADate).year=((sec_temp>>9)&0x007f)+1980;
iFile=pArg->BytesPerSector;
iSec=sec_temp+pArg->SectorsPerClust;
}
else
{
iItem++;
}
}
}
}
}while(!flag && (Cur_Clust=FAT32_GetNextCluster(Cur_Clust))!=0x0fffffff);
if(!flag)
{
return 1;
}
return 0;
}
else
{
return 2;
}
}
|