⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat1x.c

📁 PDA上的CF CARD 文件系统的建立程式
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************
File Name: FAT1x.C 1.1						*
*****************************************************************
Programmer: Huang Giun-Haur
Last Modified Date: 1999/2/1
Compiler : Gnu Cross-compiler
Platform : X86 protection mode
Usage :
	int FAT_open(const char *filename, int oflag[, unsigned pmode])
	int FAT_close(int handle)
	long read(int handle, char *buffer, unsigned count)
	long write(int handle, char *buffer, unsigned count)
	long FAT_lseek(int handle, long offset, int origin)
	long FAT_tell(int handle)
	int FAT_eof(int handle)
        int FAT_dup(int handle)
	int FAT_dup2(int oldhandle, newhandle)
	int FAT_mkdir(const char *path)
	int FAT_rmdir(const char *path)
	int FAT_remove(const char *path)
	int FAT_rename(const char *oldname, const char *newname)
	int FAT_stat(char *path, struct _stat *buffer)
	int FAT_fstat(int handle, struct _stat *buffer)
	long FAT_filelength(int handle)
	long FAT_getdiskspace()

Unfinished functions:
	int FAT_clear(void);
	int FAT_access(unsigned char *pathname, int mode);
	char FAT_scanDisk(char interactive, char fix);
	int FAT_defrag(void);
	void FAT_closeAllFilesByThread(int tid);
	void FAT_closeOrphanFiles(void);
	int FAT_flush(int fhandle);
	char FAT_scanDisk(char interactive, char fix);
	int FAT_defrag(void);
*************************************************************/

/*************************************************************
                      History
**************************************************************/
/*
 * Version: 1.3
 * Date 1999/10/05
 * Modification:
 *	(1) Borland-like FAT_findfirst(), FAT_findnext(), & FAT_findclose() 
 *	    that can handle LFN are added.
 *	(2) FAT_convertShortName() is added.
 *	(3) Document done.
 *	(4) ANSI-C is not necessary anymore.
 *	(5) CHS translation problem solved.
 *
 * Version: 1.2.2
 * Date 1999/08/23
 * Modification:
 *	(1) Chinese LFN working
 *	(2) FAT_rename() LFN supporting done
 *
 * Version: 10 build 0819
 * Date 1999/08/19
 * Modification:
 *	(1) LFN supporting for basic operations is completed
 *	    rename and findx may not work
 *	(2) can handle short chinese filename in theory (untested)
 *
 * Version: 10 build 0812
 * Date 1999/08/12
 * Modification:
 *	(1) ata.h is not required for binary release
 *	(2) mktime() in FAT_stat() has been replaced by my own code
 *	(3) The lastCluster field in file structure is now
 *	    actually in use => faster access at the end of big
 *	    files
 *	(4) LFN can be recognized, create & remove LFN not done
 *	    yet
 *
 * Version: 10 build 0702
 * Date 1999/07/02
 * Modification:
 *	(1) Add multiple partition supporting
 *	(2) Improve DOS & disk compatibility
 *
 * Version: 10 build 0703
 * Date 1999/07/03
 * Modification:
 *	(1) Add truncate
 *
 * Version: 10 build 0702
 * Date 1999/07/02
 * Modification:
 *	(1) Add multiple partition supporting
 *	(2) Improve DOS & disk compatibility
 *
 * Version: 10 build 0615
 * Date 1999/06/15
 * Modification:
 *	(1) Add FAT_rename()
 *	(2) Move FAT_rename(), _dos_findfirst(), and _dos_findnext()
 *	    to fat_ext.c
 *
 * Version: 10 build 0614
 * Date 1999/06/14
 * Modification:
 *	(1) No limit in the entry number under sub-directory
 *      (2) Add ROOT cache
 *	(3) Add cache handling code
 *	(4) Add _dos_findfirst() & _dos_findnext()
 *	(5) Add error checking code
 *	(6) Various modifications
 *
 * Version: 10
 * Date 1998/12/30
 * Modification: (To do list)
 *	(1) 子目录下的 file/dir entry 数目应无限制
 *      (2) 根目录下的 file/dir entry 数目限制 : 512
 *
 * Version: 10
 * Date 1998/12/30
 * Modification: 
 *	(1) fixed disk full 还能写入的 bug
 *          => in FAT_fwrite(), return 0 when FAT_read_root_sector() == 0
 *
 * Version: 9
 * Date 1998/12/23
 * Modification: (To do list)
 *	(1) multithread 时 FAT_dup(), FAT_dup2(), FAT_close() have bugs
 *	    => close 先如 open 般 protect
 * Version: 8
 * Date 1998/12/17
 * Modification: (To do list)
 *	(1) 档案 size 变化时 disk 空间未归还
 *	(2) Implement Continuous File I/O
 *	(3) 重整 FAT_f_search(), FAT_f_create(), Make_SubDir(), Make_SubDir_File()
 *	增加两个 function:
 *	a. 於根目录下建立合法的档案或子目录, 若成功传回档案指标, 否则传回 NULL
 *         Make_SubDir(), Make_SubDir_File() => FAT_mk_under_subdir()
 *	b. 於子目录下建立合法的档案或子目录, 若成功传回档案指标, 否则传回 NULL
 *         In FAT_f_create(), MKDIR() => FAT_mk_under_root() 
 *
 */

/*************************************************************
                      Global Definitions
**************************************************************/

//#define _MAIN_FLOW_DEBUG      // Execution Flow Debug
//#define _GNU_DEBUG
/*
#ifndef _TICKOS
#define _TICKOS
#endif
*/

/*************************************************************
 		  	Header Files
**************************************************************/
#include <sys/syscall.h>
#include <sysvar.h>
#include <time.h> 
//#include "../../RDebug/include/RDebug.h"

//#include <sys_info.h>

#ifdef __WIN32__
#include "../include/ata_emu.h"
#endif


#ifdef _PROCOMP_
  #include "/rtos/driver/FileSys/FileSys.h"
#else
  #include "../../FileSys/include/FileSys.h"
#endif


#include "../include/init.h"
#include "../include/cluster.h"
#include "../include/unicode.h"
#include "../include/fat1x.h"



#ifdef FAT_USE_PCMCIA
  
  /**** added by chilong ****/
  //#include "../pcm/cf_typedef.h"
  /**** added by chilong ****/
#ifndef __WIN32__
  #include "pcmcia/include/pcmcia.h"
#endif

  #include "../include/ata_pcc.h"
  
#else
  #include "../include/ata_pcc.h"
#endif

#ifdef FAT_CHINESE_LFN
  #include "../include/b52uni.h"
  
  /**** added by chilong 10/30/2001 ****/
  #include "../include/gb2uni.h"
  /**** added by chilong 10/30/2001 ****/
  
#endif

#ifdef MSC_DEBUG
  #include "fdebug.h"
#endif


#ifdef FAT_ID

//extern unsigned short  CFCardInCheck(void);
/*************************************************************
			Global Variables
   Notes : 1.	To be thread safe, global variables had better
		not be changed once assigned
           2. 	Global variables are for convenient use,
		eliminating the passing of many common
		parameters
           3. 	Global variables should be used as less as
		possible, and any modification on global
		variables should be marked as side-effect in
		function descriptions
   Limitations :
		FAT12 partition size is 15M bytes maximum
**************************************************************/

extern struct dLinkList *tcbSearch(threadID searchID);
//struct FAT_FILE *FATHandleTable[MAX_OPEN_FILE] = {NULL};
struct FAT_FILE **FATHandleTable;

int FATHdDriver = PRIMARY_IDE;		// PRIMARY_IDE or SECOND_IDE

/* IIIstdio, IIIstdout, IIIstderr */
//IIIFILE	_III_tick_stdin, _III_tick_stdout, _III_tick_stderr;

//static unsigned short  	FATUpdateNo;

#ifdef FAT1X_DEBUG
  char FATDebugString[80];
#endif

#ifdef FAT_ROOT_CACHE_ON
/* ROOT cache */
struct FAT_ROOT FATRootCache[FAT_ROOT_CACHE_BLOCK];

extern unsigned long FATRootReadHit;	/* ROOT read hit count */
extern unsigned long FATRootReadMiss;	/* ROOT read miss count */
extern unsigned long FATRootWriteHit;	/* ROOT write hit count */
extern unsigned long FATRootWriteMiss;	/* ROOT write miss count */
extern unsigned long FATRootSwap;	/* ROOT cache swap count */
extern unsigned long FATRootFlush;	/* ROOT cache flush count */
#endif

/* init.c */
extern char		FATAvailDrive;
/* The following are used in read_boot_sector */
extern unsigned short  	FATSecPerFAT[DRIVE_NUM];
extern unsigned long   	FATBytesPerCluster[DRIVE_NUM];
extern unsigned long  	FAT1Begin[DRIVE_NUM];
extern unsigned long  	FAT2Begin[DRIVE_NUM];
extern unsigned long  	FATRootBegin[DRIVE_NUM];
extern unsigned short  	FATTotalCluster[DRIVE_NUM];
extern unsigned short  	FATSecPerROOT[DRIVE_NUM];
extern unsigned char 	FATType[DRIVE_NUM];
extern unsigned char	FATDriveOn[DRIVE_NUM];

// added by chilong 02/19/2002
extern unsigned short	FATSecPerCluster[DRIVE_NUM];


extern int		FATDirSemaphoreID;
extern int		FATFatSemaphoreID;
extern int		FATFtableSemaphoreID;
extern int		FATAtaSemaphoreID;

extern unsigned short	FATEndOfChain[16];

// init.c
extern struct FAT_C_H_S FATDiskInfo;
extern char FATAvailDrive;
extern int FAT_init(void);

// cluster.c
#ifdef FAT_CLUSTER_CACHE_ON
	extern struct FAT_clusterCache FATClusterCache[FAT_CACHE_TAG_NO][FAT_BLOCK_PER_TAG];
#endif

#ifdef FAT_FAT_CACHE_ON
	extern struct FAT_fatCache FATFatCache[FAT_FAT_CACHE_BLOCK];
#endif

/*======================[ Functions ]========================*/

/*************************************************************
Function: FAT_releaseCFResources()
Description:
Input:
Output:
**************************************************************/
void FAT_releaseCFResources(int isCardOut)
{
  /**** modified by chilong 03/18/2002 ****/
  int i;
  int j;
  
  if (FATHandleTable == NULL)
  {
	FATErrno = ERROR_FILE_SYSTEM_NOT_INIT;
  	return;
  }

  FATErrno = 0;

  if (isCardOut == 0)
  {
  	// free all resources from the file handle table
  	for (i = 0; i < MAX_OPEN_FILE; i++)
  	{
		if (FATHandleTable[i] != NULL)
		{
			if ((FATHandleTable[i])->deviceID == FAT_ID)
			{
	  			ap_free(FATHandleTable[i]->buffer);
  				ap_free(FATHandleTable[i]);
				FATHandleTable[i] = NULL;
			}
		}
  	}
  	
  	// free memory allocated for cache
  #ifdef FAT_FAT_CACHE_ON
  	for (i = 0; i < FAT_FAT_CACHE_BLOCK; i++)
  	{
  		FATFatCache[i].drive = 0;
		FATFatCache[i].sec_num = 0;
		FATFatCache[i].lu = 0;
		FATFatCache[i].DirtySec = FALSE;
		if (FATFatCache[i].Entry != NULL)
		{
			ap_free(FATFatCache[i].Entry);
			FATFatCache[i].Entry = NULL;
		}
	}
  #endif

  #ifdef FAT_CLUSTER_CACHE_ON
  	for (i = 0; i < FAT_CACHE_TAG_NO; i++)
		for (j = 0; j < FAT_BLOCK_PER_TAG; j++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -