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

📄 mem-ffs.c

📁 mmc_sd_memory_card_driver_sample_project_files.zip spi接口的sd card driver 示例
💻 C
📖 第 1 页 / 共 5 页
字号:
// 1 = error (file doesn't exist or can't be deleted as its currently open)
int ffs_remove (const char *filename)
{
	#### ####;
	#### #####;
	##### ############;
	#### ###################[#];
	#### ########################[#];
	##### ##############;
	##### ###################;
	#### ##############;
	##### ############################## = ##########;
	##### ######################;
	#### #############################;
	##### ######################;
	##### #######;
	#### *##############;
	##### ###;

	//Check card is inserted and has been initialised
	## (########### == #)
		######(#);

	//----- FIND THE FILE -----
	################### = #############(########, &##############, &##############, &######################, &#############################, ###################, ########################);
	## (################### == ##########)		//0xffffffff = file not found
	{
		//FILE DOES NOT EXIST
		###### = #;
		######(#);
	}


	//------------------------------------
	//----- FOUND THE FILE TO DELETE -----
	//------------------------------------

	//----- CHECK FILE IS NOT BEING ACCESSED BY ANY CURRENT FILE HANDLER -----
	//if (read_cluster_number != 0xffffffff)		//0xffffffff = file not found
	//{
		### (#### = #; #### < #############; ####++)
		{
			## (########[####].#####.####.############)
			{
				## (
					(########[####].###################### == ######################) &&
					(########[####].############################# == #############################)
					)
				{
					######(#);
				}
			}
		}
	//}


	//----- SET THE 1ST CHARACTER OF THE FILE NAME TO 0xE5 TO INDICATE ITS A DELETED ENTRY IN THE DIRECTORY -----
	###################[#] = ####;
	
	//----- STORE THE MODIFIED DIRECTORY ENTRY BACK TO THE DISK -----
	##################################(###################, ########################, &##############, &##############, &###################);

	//----- CHANGE ALL ENTRIES IN THE FAT TABLE FOR THIS FILE BACK TO 0 TO INDICATE THE CLUSTERS ARE NOW FREE -----
	#####(#)
	{
		###### ####################
			####################();
		######

		//Get next cluster number
		############ = #######################(###################);

		//IF THE NEXT CLUSTER IS IN THE SAME AS THIS CLUSTER THEN JUST UPDATE THE SECTOR BUFFER
		//(If we don't do this then for each change to the FAT table we have to do a sector read followed by 2 sector writes
		//as there are 2 FAT tables to update.  This makes deleting increadibly slow as the efficiency of working on a single
		//sector as much as possible before writing it and reading the next is lost.  This solution solves the problem based
		//on the assumption that most files will largely use concurrent clusters and therefore concurrent entries in the FAT table).

		### = #################;

		## (##############)
			###################### = (#####)(#################### >> #);		//FAT32 - Divide no of bytes per sector by 4 as each fat entry is 1 double word
		####
			###################### = (#####)(#################### >> #);		//FAT16 - Divide no of bytes per sector by 2 as each fat entry is 1 word

		####### = (############ / ######################);						//dw_temp now has the sector address that will need to be modifed for the next cluster entry
		### += #######;

		## (### == #######################)
		{
			//----- NEXT CLUSTER ENTRY IS IN SAME FAT TABLE SECTOR AS THE CURRENT CLUSTER ENTRY -----
			################### #= (####### * ######################);

			//Point to this entry in the FAT table
			## (##############)
			{
				############## = &##############################[#] + (################### << #);

				*##############++ = ####;										//FAT32 - 1 double word per entry
				*##############++ = ####;
				*##############++ = ####;
				*##############++ &= ####;										//(The top 4 bits are reserved and should not be modified)
			}
			####
			{
				############## = &##############################[#] + (################### << #);

				*##############++ = ####;										//FAT16 - 1 word per entry
				*##############++ = ####;
			}
		}
		####
		{
			//----- NEXT CLUSTER ENTRY IS NOT IN THE SAME FAT TABLE SECTOR - DO UPDATE AS NOMAL -----
			//(This also stores all of the previous updates to the FAT table)
			//Clear the current cluster entry
			###############################(###################, (#####) ##########);
		}




		//CHECK FOR THAT WAS THE LAST CLUSTER
		## (##############)
		{
			//FAT32
			## ((############ & ##########) >= ##########)
			{
				//There is no next cluster - all of file has been done
				#####;
			}
		}
		####
		{
			//FAT16
			## (############ >= ######)
			{
				//There is no next cluster - all of file has been done
				#####;
			}
		}
		//Check for error - shouldn't be able to happen (0 & 1 are reserved cluster numbers)
		## (############ < #)
		{
			#####;
		}
		
		################### = ############;
		## (################### < ##############################)
			############################## = ###################;
	}

	###### = #;

	//If we have free'd up some lower clusters than the current cluster to start looking in when writing new clusters then change the value
	## (####################### > ##############################)
		####################### = ##############################;

	######(#);	


}





//*********************************
//*********************************
//********** RENAME FILE **********
//*********************************
//*********************************
//Return value
// 0 = file is succesfully renamed
// 1 = error (file doesn't exist or can't be renamed as its currently open)
int ffs_rename (const char *old_filename, const char *new_filename)
{
	#### ###################[#];
	#### ########################[#];
	##### ################### = #;
	##### ##############;
	#### ##############;
	##### ######################;
	#### #############################;
	#### ####;


	//CHECK CARD IS INSERTED AND HAS BEEN INITIALISED
	## (########### == #)
		######(#);

	//----- FIND THE FILE -----
	################### = #############(############, &##############, &##############, &######################, &#############################, ###################, ########################);
	## (################### == ##########)		//0xffffffff = file not found
	{
		//FILE DOES NOT EXIST
		###### = #;
		######(#);
	}

	//------------------------------------
	//----- FOUND THE FILE TO RENAME -----
	//------------------------------------

	//----- CHECK FILE IS NOT BEING ACCESSED BY ANY CURRENT FILE HANDLER -----
	## (################### != ##########)		//0xffffffff = file not found
	{
		### (#### = #; #### < #############; ####++)
		{
			## (########[####].#####.####.############)
			{
				## (
					(########[####].###################### == ######################) &&
					(########[####].############################# == #############################)
					)
				{
					######(#);
				}
			}
		}
	}

	//CONVERT THE NEW FILENAME TO DOS FILENAME
	## (########################### (############, ###################, ########################))		//Returns 1 if filename had wildcard characters
		######(#);

	//STORE THE MODIFIED DIRECTORY ENTRY BACK TO THE DISK
	##################################(###################, ########################, &##############, &##############, &###################);

	######(#);
}





//*******************************************************
//*******************************************************
//********** CLEAR ERROR AND END OF FILE FLAGS **********
//*******************************************************
//*******************************************************
void ffs_clearerr (FFS_FILE *file_pointer)
{

	#############>#####.####.############ = #;
	#############>#####.####.########### = #;
}






//**************************************************
//**************************************************
//********** HAS END OF FILE BEEN REACHED **********
//**************************************************
//**************************************************
int ffs_feof (FFS_FILE *file_pointer)
{

	## (#############>#####.####.###########)
		######(#);
	####
		######(#);
}






//*************************************************************
//*************************************************************
//********** HAS AN ERROR OCCURED DURING FILE ACCESS **********
//*************************************************************
//*************************************************************
int ffs_ferror (FFS_FILE *file_pointer)
{

	## (#############>#####.####.############)
		######(#);
	####
		######(#);
}







//******************************************************
//******************************************************
//********** IS CARD INSERTED AND AVAILABLE ************
//******************************************************
//******************************************************
//Returns:
BYTE ffs_is_card_available (void)
{
		######(###########);
}















//*********************************************************************************************
//*********************************************************************************************
//*********************************************************************************************
//*********************************************************************************************
//****************************** DRIVER SUB FUNCTIONS BELOW HERE ******************************
//*********************************************************************************************
//*********************************************************************************************
//*********************************************************************************************
//*********************************************************************************************



//*******************************
//*******************************
//********** FIND FILE **********
//*******************************
//*******************************
//filename
//	Only 8 character DOS compatible root directory filenames are allowed.  Format is F.E where F may be between 1 and 8 characters
//	and E may be between 1 and 3 characters, null terminated.  The '*' and '?' wildcard characters are allowed.
//file_size
//	File size (bytes) will be written to here
//attribute_byte
//	Attribute byte will be written to here
//directory_entry_sector
//	Sector that contains the files directory entry will be written to here
//directory_entry_within_sector
//	The file directory entry number within the sector that contains the file will be written to here
//read_file_name
//	8 character buffer containing the filename read from the directory entry (may be needed if using this function with wildcard characters)
//read_file_extension
//	3 character buffer containing the filename extension read from the directory entry (may be needed if using this function with wildcard characters)
//
//Returns
//	file start cluster number (0xffffffff = file not found)
//
//NOTES
//	ffs_overwrite_last_directory_file_name may be used to modify the file entry in the directory after finding it with this function

DWORD ffs_find_file (const char *filename, DWORD *file_size, BYTE *attribute_byte, DWORD *directory_entry_sector,
					 #### *#############################, #### *##############, #### *###################)
{
	#### ####;
	#### ################;
	#### ##################;
	#### ###################[#];
	#### ########################[#];
	##### ###################;
	

	//----- CHECK CARD IS INSERTED AND HAS BEEN INITIALISED -----
	##(########### == #)
		######((#####)##########);

	//----- CONVERT NULL TERMINATED FILE NAME TO 8 CHARACTER DOS FILENAME -----
	########################### (########, ###################, ########################);

	################## = #;
	//----- GET EACH DIRECTORY ENTRY UNTIL WE FIND THE MATCHING FILE -----
	##### (#)
	{
		###### ####################
			####################();
		######

		//GET NEXT ENTRY
		## (############################# (##############, ###################, ##############, #########,
											&###################, ##################, ######################,
											#############################) == #)
		{
			###### = #;								//Deselect the card
			######((#####)##########);				//Reached end of directory
		}
		################## = #;

		################ = #;								//Default to this is the file

		//If 1st value is 0x00 then entry has never been used (erased entries are 0xe5) so 0x00 is the end of used directory marker)
		## (*(############## + #) == ####)
		{
			###### = #;						//Deselect the card
			######((#####)##########);
		}

		//If 1st value is 0xe5 then entry has been deleted
		## (*(############## + #) == ####)

⌨️ 快捷键说明

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