📄 fs.cpp
字号:
#include "stdafx.h"
#include "fs.h"
#ifndef WIN32
typedef struct file_tag{
int _cnt;
int _file;
}FILE;
#endif
void SCI_InitFs(void);
#define DISK_MAX_NUM 4
DISK_INFO_P gDisk[DISK_MAX_NUM];
int gDiskCount;
#define FILE_CTRL_NUM 16
FILE gFileCtrl[FILE_CTRL_NUM];
/**
* void DISK_Init(void)
*
* update 2008/12/1
*
* check 0
*/
void DISK_Init(void)
{
gDiskCount = 0;
FS_AddFlashDisk(&gDisk[0]);
gDisk[0]->mFInit('c');
if(!gDisk[0]->mFIsFormat()){
gDisk[0]->mFfomat('c');
}
gDiskCount++;
SCI_InitFs();
}
/**
* void SCI_InitFs(void)
*
* update 2008/12/1
*
* check 0
*/
void SCI_InitFs(void)
{
for(int i=0; i<FILE_CTRL_NUM; i++){
gFileCtrl[i]._file = 0;
gFileCtrl[i]._cnt = 0;
}
}
/**
* FILE *SCI_GetFreeFileCtrl(void)
*
* update 2008/12/1
*
* check 0
*/
FILE *SCI_GetFreeFileCtrl(void)
{
FILE *hFile = NULL;
for(int i=0; i<FILE_CTRL_NUM; i++){
if(0 == gFileCtrl[i]._file){
hFile = &gFileCtrl[i];
}
}
return( hFile );
}
/**
* FILE *SCI_fopen(char *FileName,char *mode)
*
* update 2008/12/1
*
* check 0
*/
FILE *SCI_fopen(char *FileName,char *mode)
{
FILE *hFile;
hFile = SCI_GetFreeFileCtrl();
if(0 != hFile){
hFile->_file = gDisk[hFile->_cnt]->mFopen(FileName,mode);
if(0 == hFile->_file){
hFile = NULL;
}
}
return ( hFile );
}
/**
* int SCI_fclose(FILE *hFile)
*
* update 2008/12/1
*
* check 0
*/
int SCI_fclose(FILE *hFile)
{
if(NULL != hFile){
if(0 != hFile->_file){
gDisk[hFile->_cnt]->mFclose(hFile->_file);
hFile->_file = 0;
}
}
return(0);
}
/**
* size_t SCI_fread( void *buffer, size_t size, size_t count, FILE *stream )
*
* update 2008/12/1
*
* check 0
*/
size_t SCI_fread( void *buffer, size_t size, size_t count, FILE *stream )
{
int n = 0;
if(NULL != stream ){
if(0 != stream->_file){
n = gDisk[stream->_cnt]->mFread((BYTE*)buffer, size,count, stream->_file);
}
}
return( n );
}
/**
* size_t SCI_fwrite( const void *buffer, size_t size, size_t count, FILE *stream )
*
* update 2008/12/1
*
* check 0
*/
size_t SCI_fwrite( const void *buffer, size_t size, size_t count, FILE *stream )
{
int n = 0;
if(NULL != stream ){
if(0 != stream->_file){
n = gDisk[stream->_cnt]->mFwrite((BYTE*)buffer, size,count, stream->_file);
}
}
return( n );
}
/**
* int SCI_feof( FILE *stream )
*
* update 2008/12/1
*
* check 0
*/
int SCI_feof( FILE *stream )
{
int Result = 0;
if(NULL != stream ){
if(0 != stream->_file){
Result = gDisk[stream->_cnt]->mFfeof( stream->_file );
}
}
return( Result );
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*--------调试 ycdbox@126.com------------------------------------------------*/
/* 有BUG请指出 ycdbox@126.com */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
void FS_Test(void)
{
FILE *hFile;
FILE *pFile;
BYTE ch;
pFile = fopen("D:\\a.rar","rb");
if(pFile == NULL){
return;
}
hFile = SCI_fopen("C:\\a.txt","w");
if( NULL == hFile ){
fclose(pFile);
return;
}
while(!feof(pFile)){
fread(&ch,1,1,pFile);
if(feof(pFile)){
break;
}
SCI_fwrite(&ch,1,1,hFile);
}
SCI_fclose(hFile);
fclose(pFile);
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
//-----------------------------------
pFile = fopen("D:\\b.rar","wb");
if(pFile == NULL){
return;
}
hFile = SCI_fopen("C:\\a.txt","r");
if( NULL == hFile ){
fclose(pFile);
return;
}
while(!SCI_feof(hFile)){
SCI_fread(&ch,1,1,hFile);
fwrite(&ch,1,1,pFile);
}
SCI_fclose(hFile);
fclose(pFile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -