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

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

?? fat32_filelib.c

?? FAT32代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//					        FAT32 File IO Library
//								    V2.0
// 	  							 Rob Riglar
//						    Copyright 2003 - 2007
//
//   					  Email: rob@robriglar.com
//
//-----------------------------------------------------------------------------
//
// This file is part of FAT32 File IO Library.
//
// FAT32 File IO Library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// FAT32 File IO Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FAT32 File IO Library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include "FAT32_Definitions.h"
#include "FAT32_Base.h"
#include "FAT32_Table.h"
#include "FAT32_Access.h"
#include "FAT32_Write.h"
#include "FAT32_Misc.h"
#include "FAT32_Filestring.h"
#include "FAT32_Filelib.h"

//-----------------------------------------------------------------------------
// Locals
//-----------------------------------------------------------------------------
static FL_FILE		Files[MAX_OPEN_FILES];
static int			Filelib_Init = FALSE;

// Macro for checking if file lib is initialised
#define CHECK_FL_INIT()		{ if (Filelib_Init==FALSE) _fl_init(); }

//-----------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
static BOOL				_open_directory(char *path, UINT32 *pathCluster);
static FL_FILE*			_find_spare_file();
static void				_fl_init();
static FL_FILE*			_read_file(char *path);
static BOOL				_write_block(FL_FILE *file, BYTE *data, UINT32 length);
static FL_FILE*			_create_file(char *filename, UINT32 size);

//-----------------------------------------------------------------------------
// _fl_init: Initialise File Library
//-----------------------------------------------------------------------------
static void _fl_init()
{
	int i;
	for (i=0;i<MAX_OPEN_FILES;i++)
		Files[i].inUse = FALSE;

	Filelib_Init = TRUE;
}
//-----------------------------------------------------------------------------
// _find_spare_file: Find a slot in the open files buffer for a new file
//-----------------------------------------------------------------------------
static FL_FILE* _find_spare_file()
{
	int i;
	int freeFile = -1;
	for (i=0;i<MAX_OPEN_FILES;i++)
		if (Files[i].inUse == FALSE)
		{
			freeFile = i;
			break;
		}

	if (freeFile!=-1)
		return &Files[freeFile];
	else
		return NULL;
}
//-----------------------------------------------------------------------------
// _check_file_open: Returns true if the file is already open
//-----------------------------------------------------------------------------
static BOOL _check_file_open(FL_FILE* file)
{
	int i;

	if (file==NULL)
		return FALSE;

	// Compare open files
	for (i=0;i<MAX_OPEN_FILES;i++)
		if ( (Files[i].inUse) && (&Files[i]!=file) )
		{
			// Compare path and name
			if ( (FileString_Compare(Files[i].path,file->path)) && (FileString_Compare(Files[i].filename,file->filename)) )
				return TRUE;
		}

	return FALSE;
}
//-----------------------------------------------------------------------------
// _open_directory: Cycle through path string to find the start cluster
// address of the highest subdir.
//-----------------------------------------------------------------------------
static BOOL _open_directory(char *path, UINT32 *pathCluster)
{
	int levels;
	int sublevel;
	char currentfolder[MAX_LONG_FILENAME];
	FAT32_ShortEntry sfEntry;
	UINT32 startcluster;

	// Set starting cluster to root cluster
	startcluster = FAT32_GetRootCluster();

	// Find number of levels
	levels = FileString_PathTotalLevels(path);

	// Cycle through each level and get the start sector
	for (sublevel=0;sublevel<(levels+1);sublevel++) 
	{
		FileString_GetSubString(path, sublevel, currentfolder);

		// Find clusteraddress for folder (currentfolder) 
		if (FAT32_GetFileEntry(startcluster, currentfolder,&sfEntry))
			startcluster = (((UINT32)sfEntry.FstClusHI)<<16) + sfEntry.FstClusLO;
		else
			return FALSE;
	}

	*pathCluster = startcluster;
	return TRUE;
}

//-----------------------------------------------------------------------------
//								External API
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// fl_shutdown: Call before shutting down system
//-----------------------------------------------------------------------------
void fl_shutdown()
{
	// If first call to library, initialise
	CHECK_FL_INIT();

	FAT32_PurgeFATBuffer();
}
//-----------------------------------------------------------------------------
// fopen: Open or Create a file for reading or writing
//-----------------------------------------------------------------------------
FL_FILE* fl_fopen(char *path, char *mode)
{
	int modlen, i;
	FL_FILE* file; 

	BOOL read = FALSE;
	BOOL write = FALSE;
	BOOL append = FALSE;
	BOOL binary = FALSE;
	BOOL create = FALSE;
	BOOL erase = FALSE;

	// If first call to library, initialise
	CHECK_FL_INIT();

	if ((path==NULL) || (mode==NULL))
		return NULL;

	modlen = (int)strlen(mode);

	// Supported Modes:
	// "r" Open a file for reading. The file must exist. 
	// "w" Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.  
	// "a" Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist. 
	// "r+" Open a file for update both reading and writing. The file must exist. 
	// "w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. 
	// "a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist. 

	for (i=0;i<modlen;i++)
	{
		switch (tolower(mode[i]))
		{
		case 'r':
			read = TRUE;
			break;
		case 'w':
			write = TRUE;
			erase = TRUE;
			create = TRUE;
			break;
		case 'a':
			write = TRUE;
			append = TRUE;
			create = TRUE;
			break;
		case '+':
			if (read)
				write = TRUE;
			else if (write)
			{
				read = TRUE;
				erase = TRUE;
				create = TRUE;
			}
			else if (append)
			{
				read = TRUE;
				write = TRUE;
				append = TRUE;
				create = TRUE;
			}
			break;
		case 'b':
			binary = TRUE;
			break;
		}
	}
	
	file = NULL;

	// Read
	if (read)
		file = _read_file(path);

	// Create New
#ifdef INCLUDE_WRITE_SUPPORT
	if ( (file==NULL) && (create) )
		file = _create_file(path, 0);
#else
	create = FALSE;
	write = FALSE;
	append = FALSE;
#endif

	// Write Existing
	if ( !create && !read && (write || append) )
		file = _read_file(path);

	if (file!=NULL)
	{
		file->Read = read;
		file->Write = write;
		file->Append = append;
		file->Binary = binary;
		file->Erase = erase;
	}

	return file;	
}
//-----------------------------------------------------------------------------
// _read_file: Open a file for reading
//-----------------------------------------------------------------------------
static FL_FILE* _read_file(char *path)
{
	FL_FILE* file; 
	FAT32_ShortEntry sfEntry;

	// If first call to library, initialise
	CHECK_FL_INIT();

	file = _find_spare_file();
	if (file==NULL)
		return NULL;

	// Clear filename
	memset(file->path, '\n', sizeof(file->path));
	memset(file->filename, '\n', sizeof(file->filename));

	// Split full path into filename and directory path
	FileString_SplitPath(path, file->path, file->filename);

	// Check if file already open
	if (_check_file_open(file))
		return FALSE;

	// If file is in the root dir
	if (file->path[0]==0)
	{
		file->parentcluster = FAT32_GetRootCluster();
		file->inRoot = TRUE;
	}
	else
	{
		file->inRoot = FALSE;

		// Find parent directory start cluster
		if (!_open_directory(file->path, &file->parentcluster))
			return NULL;
	}

	// Using dir cluster address search for filename
	if (FAT32_GetFileEntry(file->parentcluster, file->filename,&sfEntry))
	{
		// Initialise file details
		memcpy(file->shortfilename, sfEntry.Name, 11);
		file->filelength = sfEntry.FileSize;
		file->bytenum = 0;
		file->startcluster = (((UINT32)sfEntry.FstClusHI)<<16) + sfEntry.FstClusLO;
		file->currentBlock = 0xFFFFFFFF;
		file->inUse = TRUE;

		FAT32_PurgeFATBuffer();

		return file;
	}

	return NULL;
}
//-----------------------------------------------------------------------------
// fl_fclose: Close an open file
//-----------------------------------------------------------------------------
void fl_fclose(FL_FILE *file)
{
	// If first call to library, initialise
	CHECK_FL_INIT();

	if (file!=NULL)
	{
		file->bytenum = 0;
		file->filelength = 0;
		file->startcluster = 0;
		file->currentBlock = 0xFFFFFFFF;
		file->inUse = FALSE;

		FAT32_PurgeFATBuffer();
	}
}
//-----------------------------------------------------------------------------
// fl_fgetc: Get a character in the stream
//-----------------------------------------------------------------------------
int fl_fgetc(FL_FILE *file)
{
	UINT32 sector;
	UINT32 offset;	
	BYTE returnchar=0;

	// If first call to library, initialise
	CHECK_FL_INIT();

	if (file==NULL)
		return -1;

	// Check if file open
	if (file->inUse==FALSE)
		return -1;

	// No read permissions
	if (file->Read==FALSE)
		return -1;

	// Check if read past end of file
	if (file->bytenum>=file->filelength)
		return -1;

	// Calculations for file position
	sector = file->bytenum / 512;
	offset = file->bytenum - (sector*512);

	// If file block not already loaded
	if (file->currentBlock!=sector)
	{
		// Read the appropriate sector
		if (!FAT32_SectorReader(file->startcluster, sector)) 
			return -1;

		// Copy to file's buffer
        memcpy(file->filebuf, FATFS_Internal.currentsector, 512);
		file->currentBlock=sector;
	}

	// Get the data block
	returnchar = file->filebuf[offset];

	// Increase next read position
	file->bytenum++;

	// Return character read
	return returnchar;
}
//-----------------------------------------------------------------------------
// fl_fread: Read a block of data from the file
//-----------------------------------------------------------------------------
int fl_fread (FL_FILE *file, BYTE * buffer, UINT32 count)
{
	UINT32 sector;
	UINT32 offset;
	UINT32 totalSectors;
	UINT32 bytesRead;
	UINT32 thisReadCount;
	UINT32 i;

	// If first call to library, initialise
	CHECK_FL_INIT();

	if (buffer==NULL || file==NULL)
		return -1;

	// Check if file open
	if (file->inUse==FALSE)
		return -1;

	// No read permissions
	if (file->Read==FALSE)
		return -1;

	// Nothing to be done
	if (count==0)
		return 0;

	// Check if read starts past end of file
	if (file->bytenum>=file->filelength)
		return -1;

	// Limit to file size
	if ( (file->bytenum + count) > file->filelength )
		count = file->filelength - file->bytenum;

	// Calculations for file position
	sector = file->bytenum / 512;
	offset = file->bytenum - (sector*512);

	// Calculate how many sectors this is
	totalSectors = (count+offset) / 512;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区二区在线观看| 欧美在线色视频| 青娱乐精品视频| 香蕉av福利精品导航| 亚洲人成网站精品片在线观看| 国产精品视频麻豆| 国产人妖乱国产精品人妖| 欧美国产一区视频在线观看| 久久九九99视频| 欧美国产一区二区| 一区精品在线播放| 中文字幕一区二区三区av| 国产精品高清亚洲| 亚洲一区二区三区四区不卡| 亚洲福利视频一区二区| 蜜桃精品视频在线观看| 久久er精品视频| 粉嫩嫩av羞羞动漫久久久| 成人丝袜18视频在线观看| 一本一道久久a久久精品| 欧美在线不卡一区| 日韩欧美激情一区| 国产日韩精品视频一区| 亚洲在线成人精品| 另类综合日韩欧美亚洲| 成人午夜电影网站| 在线一区二区观看| 精品国产污污免费网站入口 | 欧美三日本三级三级在线播放| 91久久国产综合久久| 日韩片之四级片| 中文字幕一区二区在线观看| 一区二区三区精密机械公司| 久久国产尿小便嘘嘘尿| 99久久国产综合色|国产精品| 91精品国产欧美日韩| 国产日韩欧美一区二区三区综合| 亚洲精品写真福利| 国产精品99久久久久久久女警| 91福利区一区二区三区| 久久天天做天天爱综合色| 亚洲午夜久久久| 成人永久免费视频| 欧美一级xxx| 有坂深雪av一区二区精品| 精品制服美女丁香| 在线一区二区视频| 国产精品乱码久久久久久| 日本不卡123| 欧美色手机在线观看| 国产精品欧美一级免费| 日韩有码一区二区三区| 一本久久a久久精品亚洲| 精品日韩在线观看| 亚洲gay无套男同| 91黄色激情网站| 亚洲天天做日日做天天谢日日欢| 麻豆精品蜜桃视频网站| 欧美日韩成人综合| 亚洲激情自拍视频| 91最新地址在线播放| 日本一区二区视频在线| 黑人巨大精品欧美一区| 日韩欧美国产三级电影视频| 日韩黄色免费网站| 欧美精品在线观看一区二区| 一区二区三区精品视频在线| 不卡一二三区首页| 欧美激情资源网| 国产69精品久久久久777| 久久亚洲捆绑美女| 国产成人在线视频网址| 久久毛片高清国产| 精品亚洲成a人| 精品国产一区a| 国产精品综合视频| 中文字幕精品在线不卡| 成人综合日日夜夜| 国产精品免费aⅴ片在线观看| 国产99久久久国产精品免费看 | 91麻豆精品国产91| 丝袜美腿成人在线| 日韩欧美一区在线| 国产精品正在播放| 欧美高清在线一区| 91毛片在线观看| 亚洲午夜激情网页| 日韩精品一区二区三区三区免费| 蜜臀av性久久久久蜜臀aⅴ流畅| 日韩视频免费观看高清在线视频| 奇米色777欧美一区二区| 欧美不卡一区二区三区| 国产精品一二三四| 亚洲免费观看视频| 欧美日韩国产免费| 麻豆精品一区二区av白丝在线| 久久亚洲精精品中文字幕早川悠里| 风间由美一区二区三区在线观看 | 亚洲激情自拍视频| 91精品国产综合久久小美女| 久久精品国产精品亚洲精品| 中文字幕第一区| 欧美少妇一区二区| 国内欧美视频一区二区| 综合精品久久久| 91精品国产91久久久久久一区二区| 久久国产精品99精品国产| 国产精品美女久久久久久久| 69堂亚洲精品首页| 成人综合婷婷国产精品久久| 日韩影院精彩在线| 1000部国产精品成人观看| 欧美另类变人与禽xxxxx| 国产精品一级片| 亚洲国产欧美日韩另类综合 | 国产精品二三区| 91精品欧美久久久久久动漫| 成人精品gif动图一区| 亚洲国产成人高清精品| 国产精品蜜臀av| 欧美一区二区三级| 91蜜桃婷婷狠狠久久综合9色| 免费成人性网站| 亚洲综合小说图片| 中文字幕av不卡| 日韩欧美亚洲国产另类| 欧美综合色免费| av中文字幕一区| 国产一区久久久| 九九在线精品视频| 日韩精品一二三| 一区二区三区日韩在线观看| 国产丝袜欧美中文另类| 欧美一区二区三区小说| 欧美色精品天天在线观看视频| www.欧美日韩| 国产91清纯白嫩初高中在线观看 | 精品蜜桃在线看| 欧美日韩一区二区三区在线看| 大胆亚洲人体视频| 国产福利一区二区三区视频| 久久精品久久精品| 蜜臀精品久久久久久蜜臀| 性久久久久久久久久久久| 亚洲精品国产一区二区精华液| 欧美激情综合五月色丁香小说| 久久午夜色播影院免费高清| 日韩精品一区二| 日韩三级.com| 欧美成人video| 精品粉嫩aⅴ一区二区三区四区| 日韩欧美一级二级三级久久久| 这里只有精品视频在线观看| 欧美伦理电影网| 欧美少妇性性性| 3d成人动漫网站| 日韩欧美专区在线| 26uuu国产在线精品一区二区| 2020国产精品久久精品美国| 欧美va亚洲va| 国产欧美综合在线观看第十页| 国产区在线观看成人精品| 国产精品女同互慰在线看| 亚洲日本va午夜在线影院| 亚洲区小说区图片区qvod| 亚洲乱码日产精品bd| 亚洲精品va在线观看| 日韩av一区二| 国产精品一区二区你懂的| 不卡在线视频中文字幕| 欧美在线观看18| 日韩欧美一区电影| 亚洲国产精品精华液2区45| 国产精品不卡视频| 午夜精品一区二区三区免费视频| 日韩精品国产精品| 国产美女精品一区二区三区| 91在线视频18| 欧美一区二区人人喊爽| 国产日韩欧美a| 亚洲h精品动漫在线观看| 国产毛片精品一区| 欧美羞羞免费网站| 精品日韩99亚洲| 亚洲欧美国产三级| 捆绑变态av一区二区三区| 91网上在线视频| 91精品国产乱码久久蜜臀| 最新欧美精品一区二区三区| 天天爽夜夜爽夜夜爽精品视频| 国产一区二区不卡老阿姨| 色哟哟国产精品免费观看| 日韩欧美亚洲国产精品字幕久久久 | 色拍拍在线精品视频8848| 日韩欧美国产一区二区在线播放| 日韩毛片高清在线播放| 免费久久精品视频| 在线欧美日韩国产| 久久久久久久av麻豆果冻| 亚洲第一成人在线|