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

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

?? fat16.c

?? S3C44BO的nandflash的讀寫與文件系統
?? C
?? 第 1 頁 / 共 3 頁
字號:

			Cluster = GetNextClusterNum(Cluster);
			Sector = ClusterNum2SectorNum(Cluster);
		}
	}

	return 2;
}
_FILE handles[16];

int fat_close(int handle)
{
	_FILE *fp;
	FatDateTime tm;
	BYTE* Cache;
	DIRENTRY *dir;

	if(handle <0 || handle >= sizeof(handles)/sizeof(_FILE))
		return -1;

	fp = &handles[handle];

	fat_datetime(&tm);
	fp->dir.LstAccDate = fp->dir.WrtDate = tm.Date;
	fp->dir.WrtTime = tm.Time;

	Cache = GetSectorData(fp->DirSectorNum);
	if(Cache == NULL)
		return -2;

	dir = (DIRENTRY *)Cache;
	dir += fp->DirIndex;

	memcpy((BYTE *)dir, (BYTE *)&fp->dir, sizeof(DIRENTRY));
	Flush();
    FlushFAT();
	handles[handle].valid = 0;
	return 0;
}

int fat_creat(const char* filename, BYTE attribute)
{
	DIRENTRY dir;
	char path[512];
	char name[11];
	char *p;
	DWORD ParentDirSectorNum;
	FatDateTime tm;
	_FILE file;
	DIRENTRY *pdir;
	WORD NewCluster;
	BYTE* Cache;

	// is path format correct ?
	p = get_valid_format(filename);
	if(p == NULL)
		return -2;

	//if exist this file ?
	if(fat_locate(filename, NULL) != 0xffffffff)
		return -3;

	//separate path into parent and name
	strncpy(name, &p[strlen(p)-11], 11);

	strcpy(path, filename);
	p = strrchr(path, '\\');
	*p = '\0';

	//locate parent path
	ParentDirSectorNum = fat_locate(path, NULL);
	if(ParentDirSectorNum == 0xffffffff)
		return -4;

	//fill dir attributes
	memset((BYTE *)&dir, 0, sizeof(dir));
	memcpy((BYTE *)(dir.deName), name, 11);
	dir.deAttributes = attribute;
	fat_datetime(&tm);
	dir.CrtDate = dir.LstAccDate = dir.WrtDate = tm.Date;
	dir.CrtTime = dir.WrtTime = tm.Time;
	dir.CrtTimeTenth = tm.TimeTenth;
	dir.deFileSize = 0;

	//alloc one dir
	if(AllocDir(ParentDirSectorNum, &dir, &file) != 0)
		return -5;

	//alloc a cluster
	NewCluster = AllocCluster(0);
	if(NewCluster == 0xffff)
		return -6;

	//flush to disk
	Cache = GetSectorData(file.DirSectorNum);
	if(Cache == NULL)
		return -7;

	pdir = (DIRENTRY *)Cache;
	pdir += file.DirIndex;

	pdir->deStartCluster= NewCluster;
	Flush();

	return fat_open(filename);
}

long fat_lseek(int handle, long offset, int origin)
{
	_FILE *fp;
	WORD Cluster;
	unsigned int len;
	int i;

	if(handle <0 || handle >= sizeof(handles)/sizeof(_FILE))
		return 0;

	fp = &handles[handle];

	switch(origin)
	{
	case SEEK_SET:
		{
			if(offset < 0)
				return (-1);

			fp->offset = offset;
		}
		break;

	case SEEK_CUR:
		{
			if((fp->offset + offset) <0 )
				return (-1);

			fp->offset += offset;
		}
		break;

	case SEEK_END:
		{
			if((fp->offset + offset) <0 )
				return (-1);

			fp->offset = fp->dir.deFileSize + offset;
		}
		break;

	default:
		return (-2);
	}

	// re-locate CurrentSectorNum, SectorOffset
	Cluster = fp->dir.deStartCluster;
	fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
	len = 0;

	while(Cluster != 0xffff)
	{
		for(i=0; i< SectorsPerCluster; i++)
		{
			len += BytesPerSector;

			if(len >= fp->offset)
			{
				fp->SectorOffset = fp->offset % BytesPerSector;
				return fp->offset;
			}
			
			fp->CurrentSectorNum ++;
		}

		Cluster = GetNextClusterNum(Cluster);
		fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
	}

	return handles[handle].offset;
}

int fat_open(const char* filename)
{
	int i;
	_FILE * fp = NULL;
	DWORD FirstSectorNum;

	for(i=0; i<16; i++)
	{
		if(!handles[i].valid)
		{
			fp = &handles[i];
			break;
		}
	}

	if(fp == NULL)
		return -1;

	FirstSectorNum = fat_locate(filename, fp);
	if(FirstSectorNum == 0xffffffff)
		return -2;

	fp->StartSectorNum = FirstSectorNum;
	fp->CurrentSectorNum = fp->StartSectorNum;
	fp->SectorOffset = 0;
	fp->offset = 0;
	fp->valid = 1;
	return i;
}

unsigned int fat_read(int handle, void* buffer, unsigned int bytes)
{
	BYTE* Cache;
	unsigned int read_bytes =0;
	unsigned int max_copy_bytes_in_sector;
	_FILE *fp;
	WORD Cluster;
	int i;

	if(handle <0 || handle >= sizeof(handles)/sizeof(_FILE))
		return 0;

	fp = &handles[handle];
	bytes = (fp->dir.deFileSize - fp->offset) > bytes ? bytes : (fp->dir.deFileSize - fp->offset);

	Cluster = SectorNum2ClusterNum(fp->CurrentSectorNum);

	i = (fp->CurrentSectorNum - FirstDataSector) % SectorsPerCluster;

	if(i != 0)
	{
		for(; i< SectorsPerCluster; i++)
		{
			Cache = GetSectorData(fp->CurrentSectorNum);
			if(Cache == NULL)
				return 0;

			Cache += fp->SectorOffset;
			max_copy_bytes_in_sector = (BytesPerSector - fp->SectorOffset) > (bytes - read_bytes) ? (bytes - read_bytes) : (BytesPerSector- fp->SectorOffset);
			memcpy(buffer, Cache, max_copy_bytes_in_sector);

			read_bytes += max_copy_bytes_in_sector;
			fp->SectorOffset += max_copy_bytes_in_sector;
			fp->offset += max_copy_bytes_in_sector;
			buffer = (char*)buffer + max_copy_bytes_in_sector;

			if(fp->SectorOffset == BytesPerSector)
			{
				if(i == SectorsPerCluster -1)
				{
					Cluster = GetNextClusterNum(Cluster);
					if(Cluster != 0xffff)
						fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
				}
				else
					fp->CurrentSectorNum ++;

				fp->SectorOffset = 0;
			}

			if(read_bytes == bytes)
			{
				return bytes;
			}
		}
	}
	
	while(Cluster != 0xffff)
	{
		for(i=0; i< SectorsPerCluster; i++)
		{
			Cache = GetSectorData(fp->CurrentSectorNum);
			if(Cache == NULL)
				return 0;

			Cache += fp->SectorOffset;
			max_copy_bytes_in_sector = (BytesPerSector- fp->SectorOffset) > (bytes - read_bytes) ? (bytes - read_bytes) : (BytesPerSector- fp->SectorOffset);
			memcpy(buffer, Cache, max_copy_bytes_in_sector);
			
			read_bytes += max_copy_bytes_in_sector;
			fp->SectorOffset += max_copy_bytes_in_sector;
			fp->offset += max_copy_bytes_in_sector;
			buffer = (char*)buffer + max_copy_bytes_in_sector;

			if(fp->SectorOffset == BytesPerSector)
			{				
				if(i == SectorsPerCluster -1)
				{
					Cluster = GetNextClusterNum(Cluster);
					if(Cluster != 0xffff)
						fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
				}
				else
					fp->CurrentSectorNum ++;

				fp->SectorOffset = 0;
			}

			if(read_bytes == bytes)
			{
				return bytes;
			}
		}		
	}

	return 0;
}

unsigned int fat_write(int handle, const char* buffer, unsigned int bytes)
{
	BYTE* Cache;
	unsigned int write_bytes =0;
	unsigned int max_write_bytes_in_sector;
	_FILE *fp;
	WORD Cluster;
	WORD PrevCluster;
	int i;

	if(handle <0 || handle >= sizeof(handles)/sizeof(_FILE))
		return 0;

	fp = &handles[handle];

	Cluster = SectorNum2ClusterNum(fp->CurrentSectorNum);
	PrevCluster = Cluster;

	i = (fp->CurrentSectorNum - FirstDataSector) % SectorsPerCluster;

	if(i != 0)
	{
		for(; i< SectorsPerCluster; i++)
		{
			Cache = GetSectorData(fp->CurrentSectorNum);
			if(Cache == NULL)
				return 0;

			Cache += fp->SectorOffset;
			max_write_bytes_in_sector = (BytesPerSector- fp->SectorOffset) > (bytes - write_bytes) ? (bytes - write_bytes) : (BytesPerSector - fp->SectorOffset);
			memcpy(Cache, buffer, max_write_bytes_in_sector);
			Flush();

			write_bytes += max_write_bytes_in_sector;
			fp->SectorOffset += max_write_bytes_in_sector;
			fp->offset += max_write_bytes_in_sector;
			buffer = (char*)buffer + max_write_bytes_in_sector;
			fp->dir.deFileSize +=  max_write_bytes_in_sector;

			if(fp->SectorOffset == BytesPerSector)
			{
				if(i == SectorsPerCluster -1)
				{
					PrevCluster = Cluster;
					Cluster = GetNextClusterNum(Cluster);
					if(Cluster != 0xffff)
						fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
					else
					{
						Cluster = AllocCluster(PrevCluster);
						if(Cluster == 0xffff)
							return 0;
						
						fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
					}
				}
				else
					fp->CurrentSectorNum ++;

				fp->SectorOffset = 0;
			}

			if(write_bytes == bytes)
			{
				return bytes;
			}
		}
	}

	for(;;)
	{
		for(i=0; i< SectorsPerCluster; i++)
		{
			Cache = GetSectorData(fp->CurrentSectorNum);
			if(Cache == NULL)
				return 0;

			Cache += fp->SectorOffset;
			max_write_bytes_in_sector = (BytesPerSector - fp->SectorOffset) > (bytes - write_bytes) ? (bytes - write_bytes) : (BytesPerSector - fp->SectorOffset);
			memcpy(Cache, buffer, max_write_bytes_in_sector);
			Flush();

			write_bytes += max_write_bytes_in_sector;
			fp->SectorOffset += max_write_bytes_in_sector;
			fp->offset += max_write_bytes_in_sector;
			buffer = (char*)buffer + max_write_bytes_in_sector;
			fp->dir.deFileSize +=  max_write_bytes_in_sector;

			if(fp->SectorOffset == BytesPerSector)
			{
				if(i == SectorsPerCluster -1)
				{
					PrevCluster = Cluster;
					Cluster = GetNextClusterNum(Cluster);
					if(Cluster != 0xffff)
						fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
					else
					{
						Cluster = AllocCluster(PrevCluster);
						if(Cluster == 0xffff)
							return 0;
						
						fp->CurrentSectorNum = ClusterNum2SectorNum(Cluster);
					}
				}
				else
					fp->CurrentSectorNum ++;

				fp->SectorOffset = 0;
			}

			if(write_bytes == bytes)
			{
				return bytes;
			}
		}
	}

	// we can not reach here.
	return 0;
}

int fat_remove( const char *filename)
{
	DWORD SectorNum;
	_FILE file;

	//locate
	SectorNum = fat_locate(filename, &file);
	if(SectorNum == 0xffffffff)
		return 4;

	// is it a dir ?
	if(file.dir.deAttributes & ATTR_DIRECTORY)
		return 6;

	if(DeleteDir(&file) != 0)
		return 5;

	FreeCluster(file.dir.deStartCluster);

	return 0;
}

int fat_get_stat( const char *filename, _STAT * stat)
{
	DWORD SectorNum;
	_FILE file;

	//locate
	SectorNum = fat_locate(filename, &file);
	if(SectorNum == 0xffffffff)
		return 1;

	stat->Attr = file.dir.deAttributes;
	stat->CrtDate = file.dir.CrtDate;
	stat->CrtTime = file.dir.CrtTime;
	stat->CrtTimeTenth = file.dir.CrtTimeTenth;
	stat->FileSize = file.dir.deFileSize;
	stat->LstAccDate = file.dir.LstAccDate;
	stat->WrtDate = file.dir.WrtDate;
	stat->WrtTime = file.dir.WrtTime;

	return 0;
}

int fat_set_stat( const char *filename, _STAT * stat)
{
	DWORD SectorNum;
	_FILE file;
	BYTE* Cache;
	DIRENTRY *dir;

	//locate
	SectorNum = fat_locate(filename, &file);
	if(SectorNum == 0xffffffff)
		return 1;

	file.dir.deAttributes = stat->Attr;
	file.dir.CrtDate = stat->CrtDate;
	file.dir.CrtTime = stat->CrtTime;
	file.dir.CrtTimeTenth = stat->CrtTimeTenth;
	file.dir.deFileSize = stat->FileSize;
	file.dir.LstAccDate = stat->LstAccDate;
	file.dir.WrtDate = stat->WrtDate;
	file.dir.WrtTime = stat->WrtTime;

	Cache = GetSectorData(file.DirSectorNum);
	if(Cache == NULL)
		return 2;

	dir = (DIRENTRY *)Cache;
	dir += file.DirIndex;

	memcpy((BYTE *)dir, (BYTE *)&file.dir, sizeof(DIRENTRY));
	Flush();

	return 0;
}


int fat_rename( const char *oldname, const char *newname )
{
	DIRENTRY dir;
	char path[512];
	char newpath[512];
	char name[11];
	char new_name[11];
	char *p;
	DWORD ParentDirSectorNum;
	_FILE old_file;

	//
	//check oldname file
	//

	// is path format correct ?
	p = get_valid_format(oldname);
	if(p == NULL)
		return -2;

	//if exist this file ?
	if(fat_locate(oldname, &old_file) == 0xffffffff)
		return -3;

	//separate path into parent and name
	strncpy(name, &p[strlen(p)-11], 11);

	strcpy(path, oldname);
	p = strrchr(path, '\\');
	*p = '\0';


	//
	//check newname file
	//

	if(strchr(newname, '\\') != NULL)
		return -2;

	sprintf(newpath, "%s\\%s", path, newname);

	// is path format correct ?
	p = get_valid_format(newpath);
	if(p == NULL)
		return -2;

	//if exist this file ?
	if(fat_locate(newpath, NULL) != 0xffffffff)
		return -3;

	//separate path into parent and name
	strncpy(new_name, &p[strlen(p)-11], 11);



	//locate parent path
	ParentDirSectorNum = fat_locate(path, NULL);
	if(ParentDirSectorNum == 0xffffffff)
		return -4;

	//fill dir attributes
	memcpy((BYTE *)&dir,(BYTE *)(&old_file.dir), sizeof(DIRENTRY));
	memcpy((BYTE *)dir.deName, new_name, 11);

	//alloc one dir
	if(AllocDir(ParentDirSectorNum, &dir, NULL) != 0)
		return -5;

	//delete old one
	if(DeleteDir(&old_file) != 0)
		return -6;

	return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区在线看| 99久久精品免费看国产免费软件| 91久久精品午夜一区二区| 中文字幕一区二区三区四区不卡| 成人午夜免费电影| 亚洲欧美怡红院| 日本韩国欧美在线| 婷婷开心久久网| 日韩一区二区三区视频在线 | 在线观看成人小视频| 亚洲自拍偷拍图区| 777奇米成人网| 韩国视频一区二区| 国产丝袜欧美中文另类| 91免费看视频| 免费在线观看精品| 中文字幕精品一区二区精品绿巨人 | 国内精品伊人久久久久av影院| 久久久综合精品| 91免费版pro下载短视频| 亚洲国产乱码最新视频| 欧美成va人片在线观看| www.亚洲国产| 视频在线观看国产精品| 日本一区二区三区四区| 欧美日韩一卡二卡三卡| 国产精品一区二区不卡| 亚洲综合丝袜美腿| 精品国免费一区二区三区| www.成人在线| 蜜桃av一区二区| 亚洲色大成网站www久久九九| 欧美日韩不卡一区二区| 国产精品66部| 日韩精品每日更新| 亚洲天堂中文字幕| 日韩欧美国产精品| 色综合网色综合| 激情小说欧美图片| 亚洲大片免费看| 中文字幕在线免费不卡| 在线不卡一区二区| 色综合久久综合网| 国产高清成人在线| 日本系列欧美系列| 亚洲激情成人在线| 久久久99免费| 67194成人在线观看| 93久久精品日日躁夜夜躁欧美| 久久精品99国产国产精| 亚洲综合丁香婷婷六月香| 日本一区二区三区国色天香| 日韩区在线观看| 色拍拍在线精品视频8848| 国产成人啪免费观看软件 | 亚洲色图欧美偷拍| www国产成人免费观看视频 深夜成人网| 色天天综合色天天久久| 成年人网站91| 激情图片小说一区| 麻豆精品一区二区三区| 五月天婷婷综合| 一区二区不卡在线播放 | 精品电影一区二区三区| 欧美嫩在线观看| 欧美在线视频你懂得| 99re热视频精品| 99久久久无码国产精品| 成人午夜免费av| 懂色av一区二区夜夜嗨| 国产成人免费视频一区| 国产专区综合网| 寂寞少妇一区二区三区| 麻豆精品在线播放| 激情av综合网| 极品少妇xxxx精品少妇偷拍| 久久疯狂做爰流白浆xx| 青青青爽久久午夜综合久久午夜| 天天综合日日夜夜精品| 日本vs亚洲vs韩国一区三区二区| 日韩电影免费一区| 日本伊人色综合网| 久久精品国产一区二区| 狠狠色丁香久久婷婷综合_中| 久久国内精品自在自线400部| 久久99在线观看| 国产乱理伦片在线观看夜一区| 国产精品自拍一区| 成人黄色小视频| 色综合天天综合网天天看片 | 欧美日韩午夜在线| 欧美一区二区黄色| 精品久久国产字幕高潮| 久久久久久久久蜜桃| 欧美高清在线一区二区| 亚洲欧美另类在线| 亚洲成在人线在线播放| 久久成人久久爱| 国产91精品在线观看| 一本色道a无线码一区v| 91精品国产综合久久小美女| 精品国产乱码久久久久久夜甘婷婷 | 久久久精品免费免费| 国产精品私人影院| 亚洲一区二区精品久久av| 麻豆成人免费电影| 国产a级毛片一区| 色婷婷综合五月| 日韩欧美一二三区| 国产精品短视频| 日韩经典一区二区| 国产 欧美在线| 欧美主播一区二区三区美女| 欧美刺激脚交jootjob| 中文成人综合网| 午夜精品福利一区二区蜜股av| 久草热8精品视频在线观看| 不卡av电影在线播放| 欧美高清hd18日本| 国产三级精品在线| 日韩电影一区二区三区四区| 不卡一区中文字幕| 在线播放中文字幕一区| 国产精品国产精品国产专区不片| 亚洲妇女屁股眼交7| 国产成人av一区二区三区在线| 91在线无精精品入口| 亚洲精品在线三区| 亚洲午夜久久久久久久久电影院 | 91精品欧美综合在线观看最新 | 中文字幕精品三区| 日本伊人精品一区二区三区观看方式| 成人一区二区三区| 日韩一区二区精品葵司在线| 国产精品久久久一本精品| 麻豆一区二区三| 欧美特级限制片免费在线观看| 久久蜜臀精品av| 日本vs亚洲vs韩国一区三区二区| 91美女在线看| 国产精品视频免费| 国产资源精品在线观看| 欧美精品日日鲁夜夜添| 亚洲免费视频中文字幕| 国产成人亚洲精品青草天美| 日韩免费电影一区| 婷婷久久综合九色综合伊人色| 99精品视频一区二区三区| 久久久久久久久久电影| 日本成人在线一区| 欧美色视频在线观看| 一区二区三区在线免费观看| 国产一区二区三区国产| 日韩欧美中文字幕精品| 日韩avvvv在线播放| 欧美制服丝袜第一页| 亚洲精品写真福利| 99re热这里只有精品视频| 国产欧美视频在线观看| 国内精品国产成人国产三级粉色| 3atv一区二区三区| 香蕉乱码成人久久天堂爱免费| 在线观看日产精品| 亚洲综合区在线| 一本色道亚洲精品aⅴ| 亚洲日本欧美天堂| 91理论电影在线观看| 成人欧美一区二区三区在线播放| 丰满白嫩尤物一区二区| 国产欧美精品国产国产专区| 国产精品正在播放| 中文字幕欧美激情| 成人免费毛片a| 成人欧美一区二区三区黑人麻豆| 99r精品视频| 亚洲制服丝袜一区| 欧美喷潮久久久xxxxx| 免费观看在线综合色| 欧美成人一区二区三区| 国模娜娜一区二区三区| 国产亚洲午夜高清国产拍精品| 国产传媒日韩欧美成人| 亚洲国产精品成人综合| 色婷婷综合在线| 三级在线观看一区二区| 精品福利av导航| 粉嫩久久99精品久久久久久夜 | 精品国产乱码久久久久久牛牛 | 日韩—二三区免费观看av| 日韩欧美国产精品一区| 国产精品一线二线三线| 国产精品国产三级国产| 欧美日韩中字一区| 久久国产精品第一页| 国产欧美精品一区| 欧美吞精做爰啪啪高潮| 日本乱人伦一区| 日韩电影一区二区三区四区| 久久久精品免费免费| 99久久国产免费看|