/***************************************************************/
/*
* F_FAT.c, 20070206, denny
*
* A Marconix Software Product
* Copyright(c) Marconix Co., Ltd. 2007
* All Rights Reserved. Reproduction, adaption, or
* translation without prior written permission is
* prohibited, except as allowed under the copyright laws.
*/
/***************************************************************/
#include "F_system.h"
#ifdef _READ_SD_
//#include "inc.h"
#include "F_driver.h"
#include "F_FAT.h"
tHANDLE hFile;
u8 SectorBuffer[F_SectorSize] = {0};
u8 *prSectorBuf = SectorBuffer;
FAT_HANDLE CurrentHandle;
u8 FATBuffer[FAT_BUF_SIZE] = {0};
u8 *prFATBuffer = FATBuffer;
u8 g_lfnflag = 0;
c8 g_CurrentDir[20] = ":\\";
u16 g_longfilename[MAX_LFN_BUF] = {0};
c8 g_direntry[MAX_LAYER][MAX_DIR_LEN] = {0};
u32 BufferDataGet(u8 num, u8 *buffer)
{
u8 i = 0;
u32 u32data = 0;
for(;i<num;i++)
u32data += ((u32)(buffer[i]&0xFF))<<(8*i);
return u32data;
}
void F_FAT_GetBPB(F_bpb710 *bpb, u8 *buffer)
{
u8 i = 0, j=0;
bpb->bpbBytesPerSec = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbSecPerClust = (u8)BufferDataGet(1, buffer);buffer+=1;
bpb->bpbResSectors = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbFATs = (u8)BufferDataGet(1, buffer);buffer+=1;
bpb->bpbRootDirEnts = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbSectors = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbMedia = (u8)BufferDataGet(1, buffer);buffer+=1;
bpb->bpbFATsecs = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbSecPerTrack = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbHeads = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbHiddenSecs = BufferDataGet(4, buffer);buffer+=4;
bpb->bpbHugeSectors = BufferDataGet(4, buffer);buffer+=4;
bpb->bpbBigFATsecs = BufferDataGet(4, buffer);buffer+=4;
bpb->bpbExtFlags = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbFSVers = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbRootClust = BufferDataGet(4, buffer);buffer+=4;
bpb->bpbFSInfo = (u16)BufferDataGet(2, buffer);buffer+=2;
bpb->bpbBackup = (u16)BufferDataGet(2, buffer);buffer+=2;
for(;j<12;)
bpb->bpbReserved[j++] = (u8)BufferDataGet(1, buffer);buffer+=1;
}
u8 F_FAT_Init( u8 Index)
{
F_bpb710 bpb;
F_partrecord PartInfo;
u32 TotalSectors = 0;
FAT_HANDLE *F_Handle = &CurrentHandle;
PartInfo.prStartLBA = 0;
if(F_ReadSector(hFile, PartInfo.prStartLBA, 1, prSectorBuf))
return F_ERR_DRIVER_READ_FAILURE;
if(prSectorBuf[0] == 0xE9 || (prSectorBuf[0] == 0xEB && prSectorBuf[2] == 0x90))//It's Boot Sector
{
if(prSectorBuf[510] != BOOTSIG0 || prSectorBuf[511] != BOOTSIG1 )
return F_ERR_INVALID_BOOT_SECTOR;
}
else//It's MBR
{
if(prSectorBuf[510] != BOOTSIG0 || prSectorBuf[511] != BOOTSIG1 )
return F_ERR_INVALID_MBR;
PartInfo.prStartLBA = (u32)((((u32)prSectorBuf[0x1C9])<<24) + (((u32)prSectorBuf[0x1C8])<<16)+ (((u32)prSectorBuf[0x1C7])<<8) + (prSectorBuf[0x1C6]));
if(F_ReadSector(hFile, PartInfo.prStartLBA, 1, prSectorBuf))
return F_ERR_DRIVER_READ_FAILURE;
if(prSectorBuf[510] != BOOTSIG0 || prSectorBuf[511] != BOOTSIG1 )
return F_ERR_INVALID_BOOT_SECTOR;
}
F_FAT_GetBPB(&bpb, (u8 *)(((F_bootsector710*)prSectorBuf)->bsBPB));
F_Handle->FirstDataSector = PartInfo.prStartLBA;
if(bpb.bpbFATsecs)
{
F_Handle->FatSectors = bpb.bpbFATsecs;
}
else
{
F_Handle->FatSectors = bpb.bpbBigFATsecs;
}
F_Handle->RootDirSectors = ((bpb.bpbRootDirEnts * 32) + (bpb.bpbBytesPerSec -1))/bpb.bpbBytesPerSec;
F_Handle->FirstDataSector += (bpb.bpbResSectors + bpb.bpbFATs * F_Handle->FatSectors) + F_Handle->RootDirSectors;
if(bpb.bpbSectors)
{
TotalSectors = bpb.bpbSectors;
}
else
{
TotalSectors = bpb.bpbHugeSectors;
}
F_Handle->NumClusters = (TotalSectors - (bpb.bpbResSectors + (bpb.bpbFATs * F_Handle->FatSectors) + F_Handle->RootDirSectors))/ bpb.bpbSecPerClust;
//FAT Type Determination by count of Clusters
if(F_Handle->NumClusters < 4085)
{
F_Handle->PartType = PART_TYPE_FAT12;
}
else if(F_Handle->NumClusters < 65525)
{
F_Handle->PartType = PART_TYPE_FAT16;
}
else
{
F_Handle->PartType = PART_TYPE_FAT32;
}
F_Handle->SectorsPerCluster = bpb.bpbSecPerClust;
F_Handle->FirstFATSector = bpb.bpbResSectors + PartInfo.prStartLBA;
switch (F_Handle->PartType)
{
case PART_TYPE_FAT16:
F_Handle->FirstDirCluster = 0;//first legal cluster number for FAT16 , the First Data Cluster is 2 , the Root Entry is fixed
break;
case PART_TYPE_FAT32:
F_Handle->FirstDirCluster = bpb.bpbRootClust;//Usually 2 but not required to be 2 , it should be 2 unless it's marked bad.
break;
default:
return F_ERR_UNSUPPORTED_PARTITION_TYPE;
}
if (F_Handle->PartType == PART_TYPE_FAT32)
{
F_Handle->FirstFAT2Sector=F_Handle->FirstFATSector+bpb.bpbBigFATsecs;
}
else
{
F_Handle->FirstFAT2Sector=F_Handle->FirstFATSector+bpb.bpbFATsecs;
}
F_Handle->BytesPerSector = bpb.bpbBytesPerSec;
F_Handle->currentDirCluster= F_Handle->FirstDirCluster;
/*
Uart_Printf("F_Handle->PartType = %d\n",F_Handle->PartType);
Uart_Printf("F_Handle->BytesPerSector = %d\n",F_Handle->BytesPerSector);
Uart_Printf("F_Handle->FirstDataSector = %d\n",F_Handle->FirstDataSector);
Uart_Printf("F_Handle->SectorsPerCluster = %d\n",F_Handle->SectorsPerCluster);
Uart_Printf("F_Handle->FirstFATSector = %d\n",F_Handle->FirstFATSector);
Uart_Printf("F_Handle->FirstDirCluster = %d\n",F_Handle->FirstDirCluster);
Uart_Printf("F_Handle->FatSectors = %d\n",F_Handle->FatSectors);
Uart_Printf("F_Handle->NumClusters = %d\n",F_Handle->NumClusters);
Uart_Printf("F_Handle->currentDirCluster = %d\n",F_Handle->currentDirCluster);
*/
return ERR_NONE;
}
u8 F_FAT_FolderChange(FAT_HANDLE *pHandle, c8 *FolderName)
{
F_BrowsingCursor cursor;
F_direntry de;
F_FolderInfo folderInfo;
u16 unicode[MAX_LFN_BUF] = {0};
c8 tmpname[MAX_LFN_BUF] = {0};
c8 tmpname1[MAX_LFN_BUF] = {0};
if(!strcmp(FolderName, "\\\\"))
{
F_FAT_DirInit(pHandle);
}
else
{
strcpy(tmpname, FolderName);
strupr(tmpname);
g_lfnflag = 0;
memset((u8 *)g_longfilename, 0, MAX_LFN_BUF);
F_FAT_BrowsingReset(pHandle, &cursor);
for(;F_FAT_GetNextDirEntry(pHandle, &de, &cursor, MAX_LFN_BUF, g_longfilename) == 0;)
{
if(de.deAttributes == ATTR_DIRECTORY)
{
if(g_lfnflag)
{
memcpy((u8 *)unicode, (u8 *)g_longfilename, MAX_LFN_BUF);
F_UniStrToGB2312Str(unicode, folderInfo.folderINF_Name);
g_lfnflag = 0;
strcpy(tmpname1, folderInfo.folderINF_Name);
strupr(tmpname1);
if(!strcmp(tmpname, tmpname1))
{
folderInfo.folderINF_start_cluster = de.deStartCluster + (de.deHighClust<<16);
//printf("(LFN)File Name: %s,\tStart Cluster:%d,\n", folderInfo.folderINF_Name, folderInfo.folderINF_start_cluster);
F_FAT_DirSet(folderInfo.folderINF_Name);
pHandle->currentDirCluster = folderInfo.folderINF_start_cluster;
return ERR_NONE;
}
}
else
{
F_FAT_DirEntryToSFN(&de, folderInfo.folderINF_Name, 13);
strcpy(tmpname1, folderInfo.folderINF_Name);
strupr(tmpname1);
if(!strcmp(tmpname, tmpname1))
{
folderInfo.folderINF_start_cluster = de.deStartCluster + (de.deHighClust<<16);
//printf("(SFN) File Name: %s,\tStart Cluster:%d,\n", folderInfo.folderINF_Name, folderInfo.folderINF_start_cluster);
F_FAT_DirSet(folderInfo.folderINF_Name);
pHandle->currentDirCluster = folderInfo.folderINF_start_cluster;
return ERR_NONE;
}
}
}
g_lfnflag = 0;
memset((u8 *)g_longfilename, 0, MAX_LFN_BUF);
}
}
return F_ERR_FILE_NOT_EXIST;
}
void F_FAT_DirSet(c8 *dirname)
{
u32 dirlen = strlen(dirname);
u32 latestlen = strlen(g_CurrentDir);
u8 i=0,j=0;
if(!strcmp(dirname, ".."))
{
if(la
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
mass_storage.rar (92个子文件)
mass storage
ARMFAT.mcp 139KB
ARM_USB.SearchResults 73B
ARM_USB.IMD 808B
ARM_USB.WK3 61KB
ARM_USB.IAD 1KB
SDI
SDI.c 25KB
SDI.h 3KB
main.c 3KB
ARM_USB.PR 17KB
ARM_USB.IMB 48KB
FAT
F_FileSystem.h 1KB
F_FileSystem.c 25KB
F_FAT.c 36KB
gbk2uni.H 341KB
F_driver.h 252B
F_system.c 2KB
b2u_tables.h 929KB
F_driver.c 1KB
inc.h 244B
gb2u_table.h 145KB
F_Unicode.c 4KB
F_FAT.h 11KB
F_type.h 588B
F_Unicode.h 518B
F_system.h 1KB
ARMFAT_Data
Release
ObjectCode
SDI.o 11KB
mmu.o 2KB
F_system.o 1KB
2410init.o 2KB
System.o 5KB
usbsetup.o 5KB
2410RTC.o 5KB
F_driver.o 5KB
usbout.o 5KB
usblib.o 2KB
2410slib.o 2KB
PROFILE.o 1KB
usbin.o 2KB
2410lib.o 5KB
main.o 3KB
usbmain.o 1KB
memtest.o 1KB
ARMFAT.bin 41KB
ARMFAT.axf 41KB
TargetDataWindows.tdt 126KB
CWSettingsWindows.stg 3KB
Debug
TargetDataWindows.tdt 44KB
DebugRel
TargetDataWindows.tdt 44KB
ARMLib
2410iis.c 16KB
Globe.h 826B
usbout.h 454B
usblib.h 2KB
Adc.h 191B
memtest.h 300B
2410addr.a 24KB
Adc.c 6KB
mmu.h 1KB
memtest.c 2KB
usbmain.c 4KB
PROFILE.H 437B
2410lib.c 16KB
2410usb.h 4KB
2410RTC.c 9KB
System.c 9KB
usbout.c 11KB
2410slib.h 2KB
usblib.c 8KB
option.h 2KB
2410init.s 14KB
mmu.c 3KB
usbmain.h 425B
option.a 863B
Memcfg.a 3KB
2410iis.h 771B
2410addr.h 35KB
usbsetup.h 3KB
PROFILE.C 1KB
2410RTC.h 1KB
usb.h 5KB
2410lib.h 2KB
usbsetup.c 17KB
System.h 221B
def.h 1KB
2410slib.s 7KB
usbin.h 389B
usbin.c 3KB
ARM_USB.IAB 108KB
ARM_USB.PS 302KB
ARM_USB.PRI 105KB
main.h 237B
ARM_USB.PFI 212B
ARM_USB.PO 776B
共 92 条
- 1
资源评论
jiang_busheng
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功