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

📄 file_system.h

📁 能够在单片机等小型处理器上使用的fat16文件系统
💻 H
字号:
#ifndef _FILE_SYSTEM_H
#define _FILE_SYSTEM_H
#include"file_sect_server.h"
#include<stdio.h>
//#include"init.h"
//-----------------------------------------------------------------------------
// Structure Prototypes
//-----------------------------------------------------------------------------
#define DIRECTORY_EXISTS		1
#define NO_PLACE_FOR_DIRECTORY	2
#define DIRNAME_LENGTH_ERROR	3
typedef struct 
{ 
	unsigned long block;
	unsigned offset;
}
PREV_SEARCH;


typedef struct A_FILE
{
	uint cluster_start;
	ulong sector_current;
	uint sector_direntry;
	uint offset_direntry;
	BYTE attrib;
	DWORD pos;
	DWORD size;
	BYTE isopen;
} M_FILE;

typedef WORD UNI; // Unicode character type

typedef union 
{
	struct 
	{
		BYTE seq_nr; // Bit 0..4 = seqnr, ascending, start with 1. Bit 6: final part of name
		UNI unicode1_5[5]; // Little endian
		BYTE attrib; // 0x0F
		BYTE type; // 0x00
		BYTE checksum; // int i;BYTE sum=0;for(i=0;i<11;i++) { sum=(sum>>1)+((sum&1)<<7);sum+=name[i]; }
		UNI unicode6_11[6];
		unsigned short starting_cluster; // 0x0000
		UNI unicode12_13[2];
	} lfn;
	struct 
	{
		char name[11];
		BYTE attrib;
		BYTE reserved[10];
		WORD time; // 5/6/5 bits for h/m/2*sec
		WORD date; // 7/4/5 bits for y-1980/m/d
		unsigned short starting_cluster; // 0 for empty file
		DWORD filesize;
	} sfn;
} dir_entry;

typedef struct 
{
	unsigned long block;
	unsigned offset;
	BYTE findempty;
	dir_entry* direntry;
} find_info;

#define ATTRIB_READ_ONLY 	0x01
#define ATTRIB_HIDDEN		0x02
#define ATTRIB_SYSTEM		0x04
#define ATTRIB_LABEL		0x08
#define ATTRIB_SUBDIR		0x10
#define ATTRIB_ARCHIVE		0x20

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

void m_format();
//static BYTE file_name_match(char* filename,char* direntryname);
void write_current_dir();
static ulong GetClusterOfParentDirectory();
static ulong Get_Cluster_From_Sector(unsigned long sector);
static unsigned long Get_First_Sector(ulong cluster);
static unsigned long Get_First_Block_Of_Next_Cluster(ulong cluster);
static ulong Get_Next_Cluster(ulong cluster);
static void Get_File_Name(char* direntry_name,char* file_name);
static unsigned long Get_First_Block_Directory_Cluster(unsigned long sector);
static void Clear_Cluster(ulong cluster);
static void FillDirEntry(dir_entry* direntry,char* dir_name);
void FileSys_Init();
static BYTE m_fcreate(find_info* findinfo,char* filename);
int m_fopen(M_FILE* f,char* filename,char* mode) ;
int m_feof(M_FILE* f) ;
static unsigned long fat_chain(unsigned long from,ulong nr) ;
static void fat_chain_free(ulong from) ;
static ulong fat_chain_alloc(ulong from,ulong nr) ;
ulong m_fread(M_FILE* f,BYTE* buffer,ulong count) ;
ulong m_fwrite(M_FILE* f,BYTE* buffer,ulong count) ;
void m_fclose(M_FILE* f) ;
int m_fdelete(char* name) ;
static BYTE findvalid(find_info* findinfo) ;
BYTE findfirst(find_info* findinfo,BYTE empty) ;
BYTE findnext(find_info* findinfo);

#endif

⌨️ 快捷键说明

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