亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fat16.c

?? 在s3c44b0下利用SD卡進行WAV文件(FAT16格式)播放的源程序
?? C
?? 第 1 頁 / 共 4 頁
字號:
#include <string.h>
#include "fat16.h"
#include "..\Target\44blib.h"
#include "..\Target\44b.h"

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

#define DISK_32M  32
#define DISK_16M  16

#define DEBUG_FAT        1
//#define FAT_SIZEOFWORD   8*256
#define FAT_SIZEOFWORD   478*256
//請注意每個扇區實際為528個字節,最后還有16個字節


/*
BYTE SectorBuffer[512]=
{
0xeb,0x3c,0x90,0x4d,0x53,0x44,0x4f,0x53,0x35,0x2e,0x30,0x0,0x2,0x8,0x2,0x0,
0x2,0x0,0x2,0x0,0x0,0xf8,0xef,0x0,0x3f,0x0,0xff,0x0,0x0,0x0,0x0,0x0,
0x0,0x78,0x7,0x0,0x0,0x0,0x29,0xb2,0x9d,0x40,0xa8,0x4e,0x4f,0x20,0x4e,0x41,
0x4d,0x45,0x20,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x36,0x20,0x20,0x20,0x33,0xc9,
0x8e,0xd1,0xbc,0xf0,0x7b,0x8e,0xd9,0xb8,0x0,0x20,0x8e,0xc0,0xfc,0xbd,0x0,0x7c,
0x38,0x4e,0x24,0x7d,0x24,0x8b,0xc1,0x99,0xe8,0x3c,0x1,0x72,0x1c,0x83,0xeb,0x3a,
0x66,0xa1,0x1c,0x7c,0x26,0x66,0x3b,0x7,0x26,0x8a,0x57,0xfc,0x75,0x6,0x80,0xca,
0x2,0x88,0x56,0x2,0x80,0xc3,0x10,0x73,0xeb,0x33,0xc9,0x8a,0x46,0x10,0x98,0xf7,
0x66,0x16,0x3,0x46,0x1c,0x13,0x56,0x1e,0x3,0x46,0xe,0x13,0xd1,0x8b,0x76,0x11,
0x60,0x89,0x46,0xfc,0x89,0x56,0xfe,0xb8,0x20,0x0,0xf7,0xe6,0x8b,0x5e,0xb,0x3,
0xc3,0x48,0xf7,0xf3,0x1,0x46,0xfc,0x11,0x4e,0xfe,0x61,0xbf,0x0,0x0,0xe8,0xe6,
0x0,0x72,0x39,0x26,0x38,0x2d,0x74,0x17,0x60,0xb1,0xb,0xbe,0xa1,0x7d,0xf3,0xa6,
0x61,0x74,0x32,0x4e,0x74,0x9,0x83,0xc7,0x20,0x3b,0xfb,0x72,0xe6,0xeb,0xdc,0xa0,
0xfb,0x7d,0xb4,0x7d,0x8b,0xf0,0xac,0x98,0x40,0x74,0xc,0x48,0x74,0x13,0xb4,0xe,
0xbb,0x7,0x0,0xcd,0x10,0xeb,0xef,0xa0,0xfd,0x7d,0xeb,0xe6,0xa0,0xfc,0x7d,0xeb,
0xe1,0xcd,0x16,0xcd,0x19,0x26,0x8b,0x55,0x1a,0x52,0xb0,0x1,0xbb,0x0,0x0,0xe8,
0x3b,0x0,0x72,0xe8,0x5b,0x8a,0x56,0x24,0xbe,0xb,0x7c,0x8b,0xfc,0xc7,0x46,0xf0,
0x3d,0x7d,0xc7,0x46,0xf4,0x29,0x7d,0x8c,0xd9,0x89,0x4e,0xf2,0x89,0x4e,0xf6,0xc6,
0x6,0x96,0x7d,0xcb,0xea,0x3,0x0,0x0,0x20,0xf,0xb6,0xc8,0x66,0x8b,0x46,0xf8,
0x66,0x3,0x46,0x1c,0x66,0x8b,0xd0,0x66,0xc1,0xea,0x10,0xeb,0x5e,0xf,0xb6,0xc8,
0x4a,0x4a,0x8a,0x46,0xd,0x32,0xe4,0xf7,0xe2,0x3,0x46,0xfc,0x13,0x56,0xfe,0xeb,
0x4a,0x52,0x50,0x6,0x53,0x6a,0x1,0x6a,0x10,0x91,0x8b,0x46,0x18,0x96,0x92,0x33,
0xd2,0xf7,0xf6,0x91,0xf7,0xf6,0x42,0x87,0xca,0xf7,0x76,0x1a,0x8a,0xf2,0x8a,0xe8,
0xc0,0xcc,0x2,0xa,0xcc,0xb8,0x1,0x2,0x80,0x7e,0x2,0xe,0x75,0x4,0xb4,0x42,
0x8b,0xf4,0x8a,0x56,0x24,0xcd,0x13,0x61,0x61,0x72,0xb,0x40,0x75,0x1,0x42,0x3,
0x5e,0xb,0x49,0x75,0x6,0xf8,0xc3,0x41,0xbb,0x0,0x0,0x60,0x66,0x6a,0x0,0xeb,
0xb0,0x4e,0x54,0x4c,0x44,0x52,0x20,0x20,0x20,0x20,0x20,0x20,0xd,0xa,0x52,0x65,
0x6d,0x6f,0x76,0x65,0x20,0x64,0x69,0x73,0x6b,0x73,0x20,0x6f,0x72,0x20,0x6f,0x74,
0x68,0x65,0x72,0x20,0x6d,0x65,0x64,0x69,0x61,0x2e,0xff,0xd,0xa,0x44,0x69,0x73,
0x6b,0x20,0x65,0x72,0x72,0x6f,0x72,0xff,0xd,0xa,0x50,0x72,0x65,0x73,0x73,0x20,
0x61,0x6e,0x79,0x20,0x6b,0x65,0x79,0x20,0x74,0x6f,0x20,0x72,0x65,0x73,0x74,0x61,
0x72,0x74,0xd,0xa,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xac,0xcb,0xd8,0x55,0xaa
};   //SectorBuffer
*/

BYTE SectorBuffer[512];  //SectorBuffer
//BYTE SectorSpare[16];//Nandflash的備用區,防止sectorbuffer與clusterbuffer沖突
BYTE ClusterBuffer[512][512];//ClusterBuffer
WORD FatCache[FAT_SIZEOFWORD];//FAT區的內容備份區,FAT_SIZEOFWORD為FAT空間大小
BYTE Read_Cluster_Buffer[8][512]; //文件讀取時的簇緩存
unsigned char ReadBuffer1[2500][512];//讀緩存1 大小1600k 1.56M
unsigned char ReadBuffer2[8][512];//讀緩存2 大小500k
unsigned char FileName_All[100][11];
unsigned char FileName_Select[12]={'\\'};
int m,n,init_done=0;
int buffer_add; 

//unsigned char *SectorBuffer  =  (unsigned char *) SECTOR_BUFFER1_ADDR;//暫放sector的512字節空間
//unsigned char *LongNameBuffer = (unsigned char *) LONGNAME_BUFFER_ADDR;//暫放長文件名的字節空間
//unsigned char *DirNameBuffer =  (unsigned char *) DIRNAME_BUFFER_ADDR;//暫放路徑名的字節空間 
extern unsigned char Erase_Cluster(unsigned int cluster);
extern void ReadPage(unsigned int block,unsigned int page,unsigned char *pPage);
extern int  WritePage(unsigned int block,unsigned int page,U8 *pPage); 
extern BYTE SD_ReadBlock(unsigned int blockaddr, char *recbuf);


//--------------該函數用于將磁盤格式化----------------------------//
int fat_format(unsigned char Media,unsigned char Sizeofdisk_M,unsigned char FilesysType)
{
	//PARTSECTOR   *partsector;
	//PARTRECORD   *partrecord;
	int i,j,fatsec,temp,blocknum;
	BOOTSECTOR50 *bootsector; 
	BPB50 *bpb;
	EXTBOOT *ext;
	
	const CHAR *litai_str="-LiTai- ";
	const CHAR *armsys_str="ARMSYS44B0 ";
	const CHAR *fat16_str="FAT16   ";
	blocknum=((Sizeofdisk_M<<20)>>9)>>5;
    for(i=0;i<blocknum;i++){
    //if(!(Erase_Cluster(i)))
	if(!(SD_EraseBlock_00(i)))
	{
		Uart_Printf("\nErase Nand-flash failed!%d block,it can be omitted.",i);
		//return 0;
	}
	for(j=0;j<255;j++);
    	}
	Uart_Printf("\nErase Nand-flash successfully!");

	for(i=0;i<512;i++)
	SectorBuffer[i]=0xff;
	
	if(Media==NAND_FLASH_Drv)//對Nand-flash進行格式化
	{
		 //第0個扇區為DBR
		 bootsector = (BOOTSECTOR50 *)SectorBuffer;
		 bpb = (BPB50 *)(bootsector->bsBPB);
		 ext = (EXTBOOT *)(bootsector->bsExt);
		 
		 bootsector->bsJump[0] = 0xeb;
		 bootsector->bsJump[1] = 0x03;
		 bootsector->bsJump[2] = 0x90;
		 for(i=0;i<7;i++)
		   bootsector->bsOemName[i] = *litai_str++;
		 bootsector->bsOemName[7]='\0'; 
		 bootsector->bsBootSectSig0 = BOOTSIG0;
		 bootsector->bsBootSectSig1 = BOOTSIG1;
		 
		 bpb->bpbBytesPerSec = 512;
		 bpb->bpbSecPerClust = 32;
		 if(FilesysType==PART_TYPE_FAT12||FilesysType==PART_TYPE_DOSFAT16
		 ||FilesysType==PART_TYPE_FAT16||FilesysType==PART_TYPE_FAT16LBA)
		     bpb->bpbResSectors = 1;
		 else if(FilesysType==PART_TYPE_FAT32||FilesysType==PART_TYPE_FAT32LBA)
		     bpb->bpbResSectors = 32;
		 bpb->bpbFATs = 2;
		 bpb->bpbRootDirEnts = ((bpb->bpbSecPerClust)-1-(Sizeofdisk_M >> 1)) << 4;
		 //bpb->bpbSectors = Sizeofdisk_M << 11;
		 bpb->bpbHugeSectors = Sizeofdisk_M << 11;
		 bpb->bpbMedia = 0xf0;//必須與FAT[0]一致。
		 fatsec = bpb->bpbFATsecs = Sizeofdisk_M >> 2;
		 bpb->bpbSecPerTrack = 0;
		 bpb->bpbHeads = 0;
		 bpb->bpbHiddenSecs = 0;
		 bpb->bpbHugeSectors = Sizeofdisk_M << 11;
		 
		 ext->exDriveNumber = 0x80;
		 ext->exReserved1 = 0;
		 ext->exBootSignature = EXBOOTSIG;
		 ext->exVolumeID = 0x88331446;
		 for(i=0;i<10;i++)
		 ext->exVolumeLabel[i] = *armsys_str++;
		 ext->exVolumeLabel[10]='\0';
		 for(i=0;i<7;i++)
		 ext->exFileSysType[i] = *fat16_str++;
		 ext->exFileSysType[8]='\0';
		 
		 memcpy(ClusterBuffer[0],SectorBuffer,512);
		 
		 //第1個扇區開始是FAT及FAT備份區
		 
		 for(i=0;i<512;i++)
		 SectorBuffer[i]=0x00;
		 
		 for(i=1;i<(fatsec*2+1);i++)
		 memcpy(ClusterBuffer[i],SectorBuffer,512);
		 
		 ClusterBuffer[1][0]=0xf0;//0xf8?
		 ClusterBuffer[1][1]=0xff;
		 ClusterBuffer[1][2]=0xff;
		 ClusterBuffer[1][3]=0xff;
		 
		 ClusterBuffer[fatsec+1][0]=0xf0;//0xf8?
		 ClusterBuffer[fatsec+1][1]=0xff;
		 ClusterBuffer[fatsec+1][2]=0xff;
		 ClusterBuffer[fatsec+1][3]=0xff;
		 
		 //從第fatsec*2+1個扇區開始,是根目錄區,到簇的最后,應該清零
		 for(i=fatsec*2+1;i<32;i++)
		 memcpy(ClusterBuffer[i],SectorBuffer,512);
		 
		 for(i=0;i<32;i++)//一扇區接一扇區寫入
         {
    	    for(j=0;j<255;j++);//延時
    	    //temp=WritePage(0,i,ClusterBuffer[i]);
    	    temp=SD_WriteBlock1(0,i,ClusterBuffer[i]);
    	    if(temp==0)
    	    {
    	    	Uart_Printf("\nFormat Nand-flash failed!");
    	    	return 0;
    	    }
         } 
         Uart_Printf("\nFormat Nand-flash Successfully!\n");
         return 1;
     }
	return 0;
}

 //PARTRECORD PartInfo;
 unsigned char Fat32Enabled;
 unsigned int  FirstDataSector;
 unsigned int  BytesPerSector;
 unsigned int  FATsectors;
 unsigned int  SectorsPerCluster;
 unsigned int  FirstFATSector;
 unsigned int  FirstDirSector;
 unsigned int  FileSize;
 unsigned int  FatInCache = 0; 
 DWORD RootDirSectors;	// Numbers of sectors occupied by Root Directory.
 DWORD RootDirCount;

//--------------該函數主要用于從已有的存儲介質中獲得文件系統信息------------------//
 unsigned char fatInit(void)
 {
     BOOTSECTOR50 *bootsector; 
	 BPB50 *bpb;
	 EXTBOOT *ext;	 
	 int i,j;
	 
     //for(j=0;j<255;j++);
     //ReadPage(0,0,SectorBuffer);
     SD_ReadBlock1(0,0,SectorBuffer);	
     bootsector = (BOOTSECTOR50 *)SectorBuffer;
	 bpb = (BPB50 *)(bootsector->bsBPB);
	 ext = (EXTBOOT *)(bootsector->bsExt);
     // setup global disk constants
     FirstDataSector = 0;//PartInfo.prStartLBA;
     if(bpb->bpbFATsecs)
     {
         // bpbFATsecs is non-zero and is therefore valid
         FirstDirSector = bpb->bpbResSectors + bpb->bpbFATs * bpb->bpbFATsecs;
                           //FAT12,16 =1         =2(2份FAT,其中1份為備份)×每一份FAT所占用的sector數               
     }
     
     SectorsPerCluster   = bpb->bpbSecPerClust;//每cluster的sector數目
     BytesPerSector      = bpb->bpbBytesPerSec;//每sector的字節數
     FirstFATSector      = bpb->bpbResSectors + 0;//PartInfo.prStartLBA;//FAT區的起始地址
     FATsectors          = bpb->bpbFATsecs;//每個FAT占用扇區數
     FirstDataSector  = FirstDirSector+((bpb->bpbRootDirEnts)>>4);//第一個數據扇區
     RootDirCount = bpb->bpbRootDirEnts;
     RootDirSectors = (RootDirCount*32)>>9;
           
 #ifdef DEBUG_FAT

     Uart_Printf("\n廠商標志和OS版本號 : %s",(char *)(bootsector->bsOemName));     
     //Uart_Printf("\nFirst sector     : %4x",PartInfo.prStartLBA);    
     //Uart_Printf("\nSize             : %4x",PartInfo.prSize);        
     Uart_Printf("\n每扇區字節數       : %4d",bpb->bpbBytesPerSec);    
     Uart_Printf("\n每族扇區數         : %4d",bpb->bpbSecPerClust);    
     Uart_Printf("\n保留扇區數         : %4d",bpb->bpbResSectors);     
     Uart_Printf("\n根目錄項數         : %4d",bpb->bpbRootDirEnts);
     //Uart_Printf("\n存儲卷上的扇區總數 : %4d",bpb->bpbSectors);
     Uart_Printf("\n存儲卷上的扇區總數 : %4d",bpb->bpbHugeSectors);
     Uart_Printf("\n每個FAT的扇區數    : %4d",bpb->bpbFATsecs);        
     //Uart_Printf("\nBigFatSectors    : %4x",bpb->bpbBigFATsecs);     
     Uart_Printf("\nFAT表的份數        : %4d",bpb->bpbFATs);           
     Uart_Printf("\nFAT區的起始扇區數  : %4d",FirstFATSector); 
     Uart_Printf("\n根目錄表起始扇區數 : %4d",FirstDirSector);        
     Uart_Printf("\n數據起始扇區數     : %4d",FirstDataSector);        
     //Uart_Printf("\nVolNumber        : %x",(unsigned int)(ext->exVolumeID)); 
     //Uart_Printf("\nVolumeLabel        : %s\n",(char *)(ext->exVolumeLabel));        
 #endif

     for(i=0;i<FATsectors;i++)  //作FAT區的內容拷貝
     {
        //ReadPage(0,i+1,SectorBuffer);
        SD_ReadBlock1(0,i+2,SectorBuffer);//這里+2為+保留扇區
     	for(j=0;j<256;j++)
     	{
     		FatCache[i*256+j] = SectorBuffer[j*2] + (SectorBuffer[j*2+1] << 8);
     	}
     } 
     return 0;   
 }
 
 
//一個測試程序 
void fat16_Nandflash_test(void)
{
	int x,result,i;
	int Select_music;
	char buff[]="fangajfdklsafjasfa;lfs;l";
    char buff1[]="hzlitai elec. CO.,Ltd.";

	if(1)	//fat_format(NAND_FLASH_Drv,DISK_16M,PART_TYPE_FAT16))
	{
	    if(!init_done) //只執行一次fatInit
	    {
	    	fatInit();
	    	init_done=1;
	    }
	    
		//result=fat_mkdir("\\ABCDE");
		//x = fat_creat("\\ABCDE\\CZM1933.TXT", 0x20);//0x20:txt file?
        	//Uart_Printf("\nfat_creat's file handle=%d",x);
		//fat_write(x, buff, 24);//將buff中10個字節內容寫入文件x
        //fat_write(x, buff1, 22);
		//fat_lseek(x, 0, SEEK_SET);
		//memset(buff, 0, sizeof(buff));
		//Uart_Printf("\nfat_read buff=");


		Uart_Printf("\nPlease select the num of music to play!\n");
		FlieList("ALL");
		Select_music = Uart_GetIntNum();
		memcpy(FileName_Select+1, FileName_All[Select_music], 11); 

		Uart_Printf("Reading music to RAM now!\n");
		x=fat_open( (char*) &FileName_Select );//返回的值,即x表示文件的句柄號,既handles數組中的第幾個句柄
		fat_read2(x);
		Uart_Printf("Read OK and Playing...\n");
		for(i=0;i<1000;i++);
		
		//while(1);
		/*
		fat_read(x, buff, 30);
		for(i=0;i<30;i++)
			Uart_Printf("%c",buff[i]);
		fat_close(x);
		x=fat_open("\\ABCDE\\CZM1933.txt");
		Uart_Printf("\nfat_open's result=%d",x);
		Uart_Printf("\nfat_read buff=");
		fat_read(x, buff, 15);
		for(i=0;i<15;i++)
			Uart_Printf("%c",buff[i]);
		fat_close(x);

		result=fat_rename("\\ABCDE\\CZM1933.txt", "CZM1933.txt");
		Uart_Printf("\nfat_rename's result=%d",x);

		x=fat_open("\\ABCDE\\CZM1933.txt");
		Uart_Printf("\nfat_open's result=%d",result);
		Uart_Printf("\nfat_read buff=",result);
		fat_read(x, buff, 20);
		for(i=0;i<20;i++)
			Uart_Printf("%c",buff[i]);

		result=fat_remove("\\ABCDE\\CZM1933.txt");
		Uart_Printf("\nfat_remove's result=%d",result);
		
		x=fat_open("\\ABCDE\\CZM1933.txt");
		Uart_Printf("\nfat_open's result=%d",x);

		//result=fat_rename("\\abcde\\", "abcd12");
		//Uart_Printf("\nfat_rename's result=%d",result);

		result=fat_rmdir("\\abcde");
		Uart_Printf("\nfat_rmdir's result=%d\n",result);
		*/
	}
}

void FlushFAT()//更新重寫FAT1和FAT2的內容
{
	int i,j;
	//ReadPage(0,0,SectorBuffer);
	SD_ReadBlock1(0,0,SectorBuffer);//讀扇區0+備份,寫時連扇區0一起寫
	memcpy(ClusterBuffer[0], SectorBuffer, BytesPerSector);  //backup Sector0
	
	for(i=FirstDirSector;i<SectorsPerCluster;i++)//暫不知啥意思
	{
		//ReadPage(0,i,SectorBuffer);
		SD_ReadBlock1(0,i,SectorBuffer);
		memcpy(ClusterBuffer[i],SectorBuffer,BytesPerSector);
	}
	for(i=0;i<FATsectors;i++)//備份FAT1,把已經更新過的整個FAT表,備份到ClusterBuffer
	{						 //FatCache已被更新過,0--FAT表所占扇區數  間循環 (0-239)
		for(j=0;j<256;j++)
		{
			SectorBuffer[j*2]=(FatCache[i*256+j])%256;
		    SectorBuffer[j*2+1]=(FatCache[i*256+j])>>8;
		}
		memcpy(ClusterBuffer[i+FirstFATSector],SectorBuffer,BytesPerSector);
	}
	for(i=0;i<FATsectors;i++)//備份FAT2,backup FAT field
	{
		for(j=0;j<256;j++)
		{
			SectorBuffer[j*2]=(FatCache[i*256+j])%256;
		    SectorBuffer[j*2+1]=(FatCache[i*256+j])>>8;
		}
		memcpy(ClusterBuffer[i+FirstFATSector+FATsectors],SectorBuffer,BytesPerSector);
	}
	//Erase_Cluster(0);
	SD_EraseBlock_00(0);//寫入之前,擦除當前簇;現在只擦除0簇,后面的暫時沒擦除
	for(i=0;i<SectorsPerCluster;i++)//一扇區接一扇區寫入,現在只寫0簇,后面的暫時沒寫
    {
    	for(j=0;j<255;j++);//延時
    	//WritePage(0,i,ClusterBuffer[i]);
    	SD_WriteBlock1(0,i,ClusterBuffer[i]);
    } 	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
}

//The sector number of the first sector of that cluster.
//FirstSectorofCluster = ((N – 2) * BPB_SecPerClus) + FirstDataSector;
//Because No MBR,so: clust-1!
unsigned long FirstSectorofCluster(unsigned long clust)//數據存放的cluster轉為sector
{
     return ((clust-1) * SectorsPerCluster + FirstDataSector);
}
 
// alloc a free cluster. policy is searching from prev cluster number, if no free cluster till end of fat, then search from head of fat.
// return a cluster number. 0xffff indicate faild, disk overflow.
// argument 0 : no prev cluster.
WORD AllocCluster(WORD PrevClusterNum)//查找空簇,找到后填寫0xFFFF,后重寫FAT表
{									  //返回沒用到的空簇
	static WORD LastAllocClusterNum=0;
	WORD i;

	if(LastAllocClusterNum == 0)
		LastAllocClusterNum = PrevClusterNum;

	for(i = LastAllocClusterNum; i < BytesPerSector * FATsectors / sizeof(WORD); i++)
	{
		if(FatCache[i] == 0)//如果此簇為空簇,FatCache為FAT區的內容備份區,在fatInit時被寫入信息
		{
			FatCache[i] = 0xffff;	//填寫0xFFFF,占用此簇,并且說明這是最后一簇 flag with 0xffff, this is the last cluster.
			LastAllocClusterNum = i;
			//chain this cluster to prev one.
			if(PrevClusterNum != 0)
				FatCache[PrevClusterNum] = LastAllocClusterNum;
            FlushFAT();//更新FAT表
			return LastAllocClusterNum;//返回簇號
		}
	}

	// we have to search from head of fat  //這里暫時沒運行,待以后分析
	for(i = 2; i < BytesPerSector * FATsectors / sizeof(WORD); i++)
	{
		if(FatCache[i] == 0)
		{
			FatCache[i] = 0xffff;	// flag with 0xffff, this is the last cluster.
			
			LastAllocClusterNum = i;
			
			//chain this cluster to prev one.	
			if(PrevClusterNum != 0)
				FatCache[PrevClusterNum] = LastAllocClusterNum;
			//FlushFAT();//更新FAT表
			return LastAllocClusterNum;
		}
	}
	
	return 0xffff;
} 

//return next cluster num,
//0xffff indicate no next cluster.
//Note! : this function will dirty cache!
WORD GetNextClusterNum(WORD ClusterNum)
{
	return FatCache[ClusterNum];
}

// free cluster chain.此函數應當是用于依次釋放fat鏈時
// argument 0 : no prev cluster.
void FreeCluster(WORD StartClusterNum)//何時更新disk中的FAT表?
{
	WORD Cluster;
	WORD NextCluster;

	Cluster = StartClusterNum;

	while(Cluster != 0xffff)
	{
		NextCluster = FatCache[Cluster];
		FatCache[Cluster] = 0x0000;
		Cluster = NextCluster;
	}
	//FlushFAT();//更新FAT表
}

DWORD CurrentCacheSector;
//Read a special sector into disk cache.
//NULL indicate failed.
BYTE* GetSectorData(DWORD StartSector)//LBA取得一個扇區的數據
{									  //數據放在SectorBuffer數組中
	
	unsigned int block;
	unsigned int page;
	
	//if((CurrentCacheSector == StartSector) && (StartSector != 0))
	//	return SectorBuffer;
	block=StartSector/0x08;
	page=StartSector%0x08;
	
	//ReadPage(block,page,SectorBuffer);
	SD_ReadBlock1(block,page,SectorBuffer);
	CurrentCacheSector = StartSector;
	return SectorBuffer;
}

void Flush()	//燒寫,內容在SectorBuffer中
{
	//memcpy(&((BYTE*)MemDisk)[CurrentCacheSector * Bpb.BytsPerSec], SectorCache, 512);
	int i,j;
	unsigned int block;
	unsigned int page;
	block=CurrentCacheSector/0x08;//由上一次調用GetSectorData時的參數StartSector計算簇數
	page =CurrentCacheSector%0x08;//計算扇區數
	
	memcpy(ClusterBuffer[page],SectorBuffer, BytesPerSector);
	
    if(page==0)
	{
		for(i=1;i<SectorsPerCluster;i++)//循環一簇,讀取每扇區數據,保存到緩存
		{
    		//ReadPage(block,i,SectorBuffer);
    		SD_ReadBlock1(block,i,SectorBuffer);
	    	memcpy(ClusterBuffer[i], SectorBuffer, BytesPerSector);
		}
    }
	else
	{
		for(i=0;i<page-1;i++)
    	{
        	//ReadPage(block,i,SectorBuffer);
        	SD_ReadBlock1(block,i,SectorBuffer);
	        memcpy(ClusterBuffer[i], SectorBuffer, BytesPerSector);
    	}
    	for(i=page+1;i< SectorsPerCluster;i++)
    	{
    		//ReadPage(block,i,SectorBuffer);
    		SD_ReadBlock1(block,i,SectorBuffer);
    	    memcpy(ClusterBuffer[i], SectorBuffer, BytesPerSector);
    	}   
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
最近日韩中文字幕| 欧美日韩国产小视频| 91久久人澡人人添人人爽欧美| 日本精品一区二区三区高清 | 国产欧美一区二区在线观看| 亚洲嫩草精品久久| 精品在线播放午夜| 欧美午夜在线一二页| 国产精品三级av在线播放| 日韩精品一二区| 不卡一区二区中文字幕| 国产欧美日韩另类一区| 欧美亚一区二区| 国产精品免费视频观看| 看片网站欧美日韩| 欧美三级午夜理伦三级中视频| 久久精品欧美一区二区三区不卡| 视频一区免费在线观看| 91麻豆产精品久久久久久 | 97久久超碰精品国产| 精品久久久三级丝袜| 亚洲国产视频在线| 色狠狠综合天天综合综合| 国产精品美女久久久久aⅴ| 国产综合色在线| 日韩欧美一级片| 日本欧美久久久久免费播放网| 在线看国产一区| 亚洲三级电影全部在线观看高清| 高清国产一区二区| 成人欧美一区二区三区小说| 91麻豆精品国产91久久久更新时间| 久久久影视传媒| 日韩二区在线观看| 欧美日产在线观看| 丝袜亚洲另类欧美| 日韩三级中文字幕| 久久国产麻豆精品| wwwwww.欧美系列| 国内外精品视频| 国产亚洲一二三区| 丰满放荡岳乱妇91ww| 欧美激情一区二区三区不卡| 国产a久久麻豆| 国产精品天美传媒| 日本福利一区二区| 亚洲在线免费播放| 欧美精品三级在线观看| 日韩电影在线一区二区| 精品精品欲导航| 国产精品羞羞答答xxdd| 亚洲国产精品精华液ab| 亚洲综合一区在线| 粉嫩av一区二区三区| 欧美影院一区二区| 日韩在线a电影| 欧美精选在线播放| 国产自产视频一区二区三区| 日本一区二区免费在线 | 日韩欧美综合在线| 国产综合色精品一区二区三区| 国产婷婷色一区二区三区四区 | 亚洲大片免费看| 91精品综合久久久久久| 国产精品一品视频| 亚洲福利国产精品| 精品久久久久久无| 91啪九色porn原创视频在线观看| 亚洲综合色区另类av| 日韩欧美在线综合网| 成人午夜视频在线观看| 日本不卡高清视频| 国产精品一区二区久久不卡| 亚洲影视资源网| 欧美一二区视频| 国产成人综合视频| 午夜久久久影院| 国产亚洲精品中文字幕| 欧美亚洲丝袜传媒另类| 国产乱国产乱300精品| 夜夜嗨av一区二区三区网页| 精品久久一区二区三区| 91麻豆成人久久精品二区三区| 日本va欧美va精品发布| 综合欧美亚洲日本| 日韩精品一区二区三区三区免费 | 国产精品免费观看视频| 911精品国产一区二区在线| 丰满白嫩尤物一区二区| 麻豆中文一区二区| 亚洲永久免费av| 国产精品美女久久福利网站| 精品一区二区三区免费播放| 在线观看国产精品网站| 国产一区在线看| 日韩精品欧美精品| 亚洲欧美一区二区不卡| 精品三级在线看| 51精品秘密在线观看| 91久久精品网| av资源网一区| 成人深夜在线观看| 韩国毛片一区二区三区| 日韩高清欧美激情| 性久久久久久久久| 亚洲一区二区av在线| 国产精品福利一区二区三区| 久久久久久97三级| 久久这里只有精品6| 日韩一级精品视频在线观看| 欧美精品免费视频| 欧美色图天堂网| 在线国产电影不卡| 在线一区二区观看| 99久久久国产精品免费蜜臀| 国产成人精品一区二区三区四区| 欧美日韩国产小视频在线观看| 欧美丰满少妇xxxxx高潮对白 | www.亚洲国产| 国产精品一区二区三区99| 蜜臀久久99精品久久久久久9| 午夜精品久久久久久久| 亚洲国产欧美在线人成| 五月综合激情日本mⅴ| 日韩制服丝袜av| 免费国产亚洲视频| 国产综合一区二区| 高清成人在线观看| bt7086福利一区国产| 91麻豆免费视频| 欧洲激情一区二区| 在线播放亚洲一区| 欧美mv日韩mv国产| 国产视频视频一区| 亚洲欧洲性图库| 亚洲线精品一区二区三区 | 色吊一区二区三区| 欧美日韩一区不卡| 日韩一级二级三级| 亚洲黄色小视频| 日本韩国一区二区三区| 久久99精品国产麻豆婷婷 | 国产在线视频一区二区三区| 国产白丝网站精品污在线入口| 成人av免费在线播放| 色综合婷婷久久| 欧美电影一区二区三区| 久久影院电视剧免费观看| 1区2区3区欧美| 午夜视频在线观看一区二区三区| 裸体一区二区三区| 成人久久视频在线观看| 精品视频在线免费看| 久久综合久久综合亚洲| 视频一区欧美日韩| 国产精品一区二区在线观看不卡 | 精品国产乱码91久久久久久网站| 国产香蕉久久精品综合网| 亚洲欧美偷拍卡通变态| 日韩1区2区日韩1区2区| 91黄色免费版| 精品欧美一区二区在线观看| 丁香天五香天堂综合| 欧美天天综合网| 久久精品一区二区三区不卡| 一区二区三区四区视频精品免费 | 国产精品视频免费| 午夜精品久久久| 成人av免费在线观看| 日韩精品资源二区在线| 一区二区欧美视频| 国产精品一二三区在线| 欧美视频自拍偷拍| 国产精品电影一区二区三区| 蜜臀久久久久久久| 欧美午夜精品理论片a级按摩| 精品处破学生在线二十三| 亚洲一区二区视频在线观看| 福利一区二区在线| 日韩欧美国产高清| 亚洲亚洲精品在线观看| 91啪亚洲精品| 国产性做久久久久久| 蜜臀av国产精品久久久久| 91热门视频在线观看| 国产日韩欧美综合在线| 精品一区二区在线免费观看| 国产精品丝袜在线| 色av综合在线| 91麻豆高清视频| 精品国产网站在线观看| 午夜电影一区二区三区| 色欧美片视频在线观看| 国产精品久久精品日日| 国产精品影视网| 久久久久久麻豆| 国内外精品视频| 26uuu精品一区二区在线观看| 日韩国产欧美视频| 欧美一级精品在线|