📄 fs_fun.c
字号:
#include "FS_fun.h"
struct f_info g_stFileTbl[MAXFILENUM]; //note information of one type files(name,modify time&date,size)
U16 g_nFileNum; //note the number of one type files
SPG_Time g_stFileTime; //note modify time of an appointed file
SPG_Date g_stFileDate; //note modify date of an appointed file
/**
* FS_ListFile - list all files in the storage device according to wildcard
* char *wildcard: the path and wildcard
*/
void FS_ListFile(char *wildcard)
{
//initialize file system
fs_init();
if( fs_mount(0) )
while(1);
//clear file Number
g_nFileNum = 0;
if(_findfirst(wildcard, &g_stFileTbl[g_nFileNum], D_ALL))
{
//No such file
while(1);
}
do{
g_nFileNum ++;
}while( _findnext(&g_stFileTbl[g_nFileNum]) == 0 );
}
/**
* FS_GetFileName - get the name of the appointed file
* U16 index: the index in the g_stFileTbl
* RETURN: the pointer of name string
* NULL: no such file
*/
char* FS_GetFileName(U16 index)
{
if(index < g_nFileNum)
return &g_stFileTbl[index].f_name[0];
return NULL;
}
/**
* FS_GetModifyTime - get modify time of an appointed file
* U16 index: the index in the g_stFileTbl
*/
void FS_GetModifyTime(U16 index)
{
U32 tmp;
//clear
*(U32*)(&g_stFileTime) = 0;
if(index >= g_nFileNum)
return;
//get time
tmp = (g_stFileTbl[index].f_time << 1);
*(U32*)(&g_stFileTime) = tmp;
}
/**
* FS_GetModifyDate - get modify date of an appointed file
* U16 index: the index in the g_stFileTbl
*/
void FS_GetModifyDate(U16 index)
{
U32 tmp;
//clear
*(U32*)(&g_stFileDate) = 0;
if(index >= g_nFileNum)
return;
//get date
tmp = g_stFileTbl[index].f_date;
g_stFileDate.dd = tmp & 0x0000001F;
g_stFileDate.mm = (tmp >> 5) & 0x0000000F;
g_stFileDate.yy = ((tmp >> 9) & 0x0000007F) + 1980;
}
/**
* FS_GetFileSize - get the size of the appointed file
* U16 index: the index in the g_stFileTbl
* RETURN: file size(unit: Byte)
* 0xffffffff: no such file
*/
unsigned long FS_GetFileSize(U16 index)
{
if(index < g_nFileNum)
return g_stFileTbl[index].f_size;
return 0xffffffff;
}
/**
* FS_TotalSize - get the total size of storage device
* RETURN: total size(unit: Byte)
*/
unsigned long FS_TotalSize(void)
{
struct _diskfree_t diskinfo;
unsigned long total_cluster;
//unsigned long sperc;
//unsigned long bpers;
unsigned long totalsize;
if(_getdiskfree(0, &diskinfo))
while(1);
total_cluster = diskinfo.total_clusters+13;
//sperc = diskinfo.sectors_per_cluster;
//bpers = diskinfo.bytes_per_sector;
totalsize = total_cluster * diskinfo.sectors_per_cluster * diskinfo.bytes_per_sector;
return totalsize;
}
/**
* FS_FreeSize - get the free size of storage device
* RETURN: free size(unit: Byte)
*/
unsigned long FS_FreeSize(void)
{
struct _diskfree_t diskinfo;
unsigned long free_cluster;
//unsigned long sperc;
//unsigned long bpers;
unsigned long freesize;
if(_getdiskfree(0, &diskinfo))
while(1);
free_cluster = diskinfo.avail_clusters+15;
//sperc = diskinfo.sectors_per_cluster;
//bpers = diskinfo.bytes_per_sector;
freesize = free_cluster * diskinfo.sectors_per_cluster * diskinfo.bytes_per_sector;
return freesize;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -