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

📄 kfs.h

📁 kfs嵌入式文件系统1.0.1release版 作者:Eagle 来源:http://www.embseek.com 由embseek开发
💻 H
字号:
/*

filename : kfs.h

version : 1.0.1 release

author : eagle

web : www.embseek.com

*/

#ifndef __KFS_H__
#define __KFS_H__

/*Options & types==============================*/

/*文件区首地址*/
#define 	MAX_FILE_NUM 		10
#define		MAX_FLIE_NAME_LEN	5

#ifndef NULL
#define NULL 0x00
#endif

typedef unsigned char		u8;
typedef unsigned short		u16;

/*file status*/
#define FHS_DELETED				0x0001/*0000 0000 0000 0001*/
#define FHS_OPENED				0x0002/*0000 0000 0000 0010*/
#define FHS_FSEND				0x0080/*0000 0000 1000 0000*/
#define FHS_SIZEMODIFIED		0x8000/*1000 0000 0000 0000*/
#define FHS_STATUEMODIFIED		0x4000/*0100 0000 0000 0000*/
#define FHS_NAMEMODIFIED		0x2000/*0010 0000 0000 0000*/


#define O_WRONLY 				0x01 /*0000 0001*/	/*wirte and read only*/
#define O_CREAT					0x02 /*0000 0010*/	/*create file if not exist*/	


/*head information in the file system*/
struct fshead{
	u16 	_status; 						/*file status*/
	u16 	_size;  	 					/*file size*/
	u8 		filename[MAX_FLIE_NAME_LEN];	/*file name*/	
};


/*structrue of file head informations*/
struct fhead{ 
	u16 	_status; 						/*file status*/
	u16 	_size;  	 					/*file size*/
	u8 *	_f_sadd;						/*start address of the file*/
	u8 *	_p;								/*current file point,point to the current data of the file in the fs*/
	u8 		filename[MAX_FLIE_NAME_LEN];	/*file name*/
};				

typedef struct fhead r_FILE;


/*Data=========================================*/

/*file systen start address*/
extern u8 * fs_start_add;

/*file system length*/
extern u16  fs_len;

/*current head in the file system*/
extern u8 * fs_head_add;

/*table of the file head informations*/
extern struct fhead 			fheadtable[MAX_FILE_NUM];

/*totle file number in the file system*/
extern u16 					f_num;	

/*Operations===================================*/

/****************************************
function : r_fsinit
_fs_start_add : file systen start address
_fs_end_add : file system end address
description : init the file system
****************************************/
extern void r_fsinit(u8 *_fs_start_add,u8 *_fs_end_add);


/****************************************
function : r_fopen
filename : file name less than 12byte
mode : Type of access permitted.
return : point to the opened file
description : open a file
****************************************/
extern r_FILE * r_fopen(u8 * filename, const u8 mode);


/****************************************
function : r_fdelete
fp : point to the FILE structure
return : if file was deleted return 1,\
		else return 0;
description : delete a file
****************************************/
extern void r_fdelete(r_FILE * *_fp);


/****************************************
function : r_rewind
fp : point to the FILE structure
description : rewind a file to head
****************************************/
extern void r_rewind(r_FILE *fp);


//从fp指向的用户操作文件中取出当前文件指针指向的数据(u8类型),并将文件指针的当前文件指针地址加1;
/****************************************
function : r_fgetc
fp : point to the FILE structure
return : the character read from the file
description : get a character from the file
****************************************/
extern u8 r_fgetc(r_FILE * fp);
	


//向fp指向的用户操作文件中文件指针指向的数据(u8类型)地址写入一个字符,并将文件指针的当前文件指针地址加1;
/****************************************
function : r_fputc
fp : point to the FILE structure
ch : character to put to file
return : if success return 1,else return 0;
description : put a character to file
****************************************/
extern u8 r_fputc(r_FILE * fp ,u8 ch); 



//判断是否到达文件末尾;
/****************************************
function : r_feof
fp : point to the FILE structure
return : if end return 1,else return 0
description : check if got the end of file
****************************************/
extern u8 r_feof(r_FILE * fp);



//关闭fp指向的文件
/****************************************
function : r_fclose
fp : point to the FILE structure
description : close the file
****************************************/
extern void r_fclose(r_FILE * * fp);



/****************************************
function : r_frmhead
fp : point to the FILE structure
description : remove the file head from 
				the head table
****************************************/
extern void r_frmhead(r_FILE * fp);


/****************************************
function : r_fsavehead
fp : point to the FILE structure
description : save the file head
****************************************/
extern void r_fsavehead(r_FILE * fp);


/****************************************
function : r_format
_fs_start_add : file systen start address
_fs_end_add : file system end address
description : format the file system
****************************************/
extern void r_format(u8 *_fs_start_add,u8 *_fs_end_add);

#endif //__KFS_H__

⌨️ 快捷键说明

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