📄 simulate.c
字号:
}
}
else
{
mode &= 0x0000000F;
mode -= 1;
SimFd_t[SimFd].FileType = WIN;
status = OpenWinDowsFile(name,mode);
if(status <= 0)
{
memset(&SimFd_t[SimFd],0,sizeof(SimFd_t[SimFd]));
return -1; //error
}
}
SimFd_t[SimFd].LowerFdIdx = status;
return SimFd;
}
int CloseAllFile(FS_HANDLE fd)
{
uint32 status;
if(SimFd_t[fd].FileType == FSM)
{
status = FsmClose(SimFd_t[fd].LowerFdIdx);
}
else
{
status = CloseWinDowsFile(SimFd_t[fd].LowerFdIdx);
}
if(status != ERR_NONE)
{
return status;
}
memset(&SimFd_t[fd],0,sizeof(SimFd_t[fd]));
return 0;
}
int ReadAllFile(FS_HANDLE fd, void * buffer, uint32 size)
{
if(SimFd_t[fd].FileType == FSM)
{
return FsmRead(SimFd_t[fd].LowerFdIdx, buffer, size);
}
else
return ReadWinDowsFile(SimFd_t[fd].LowerFdIdx, buffer, size);
}
int WriteAllFile(FS_HANDLE fd, void * buffer, uint32 size)
{
if(SimFd_t[fd].FileType == FSM)
{
return FsmWrite(SimFd_t[fd].LowerFdIdx,buffer,size);
}
else
return WriteWinDowsFile(SimFd_t[fd].LowerFdIdx,buffer,size);
}
int DeleteAllFile(uint8 * FileName)
{
if(strncmp(FileName,VOLNAME,strlen(VOLNAME)) == 0)
{
return FsmRemove(FileName);
}
else
return DeleteWinDowsFile(FileName);
}
int CMD_COPY(char s[],int pos[],int value[],int Segment)
{
int SrcFd,DestFd,RealReadLen,RealWriteLen;
char buffer[256+1];
if(Segment < 3)
{
FsmPrintf("\r\nERROR_PARAMETER");
return 0;
}
memset(&buffer,0,sizeof(buffer));
SrcFd = OpenAllFile(s+pos[1],FSM_OPEN_READ | FSM_OPEN_EXISTING);
if(SrcFd < 0)
{
FsmPrintf("\r\nSrcOpenError");
return 0; //SrcOpenError
}
DestFd = OpenAllFile(s+pos[2],FSM_OPEN_WRITE | FSM_CREATE_NEW);//2);
if(DestFd < 0)
{
FsmPrintf("\r\nDestOpenError");
CloseAllFile(SrcFd);
return 0; //DestOpenError
}
while((RealReadLen = ReadAllFile(SrcFd,buffer,244)) > 0)
{
RealWriteLen = WriteAllFile(DestFd,(void *)buffer,RealReadLen);
memset(buffer,0,sizeof(buffer));
}
CloseAllFile(SrcFd);
CloseAllFile(DestFd);
return 1;
}
#include "TIME.h"
#include "IO.h"
int FormatDirTime(long handle,char fstime[30],int mode)
{
int i;
char * string;
char month[5]={0};
char testwl[5]={0};
static char tmp[12][4] =
{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
string=ctime(&handle);
strncpy(testwl,string+4,3);
my_strupr(testwl);
for( i =0; i < 12; i++)
{
if(strncmp(testwl,tmp[i],3) == 0)
{
if(i < 9)
{
month[0] = 0x30; // '0'
month[1] = 0x30 + i+ 1;// 'i+1'
}
else
{
month[0] = 0x31; // '1'
month[1] = 0x30 + i + 1 -10;// 'i+1-10'
}
break;
}
}
strncpy(fstime,string+20,4);//年
if(mode == 0)
{
strncpy(fstime+4,"-",1);
strncpy(fstime+5,month,2);//月
strncpy(fstime+7,"-",1);
strncpy(fstime+8,string+8,2);//日
strncpy(fstime+10," ",1);
strncpy(fstime+11,string+11,8);//时间
}
else
{
strncpy(fstime+4,"/",1);
strncpy(fstime+5,month,2);
strncpy(fstime+7,"/",1);
strncpy(fstime+8,string+8,2);
strncpy(fstime+10,"/",1);
strncpy(fstime+11,string+11,2);
strncpy(fstime+13,"/",1);
strncpy(fstime+14,string+14,2);
strncpy(fstime+16,"/",1);
strncpy(fstime+17,string+17,2);
}
return 0;
}
int DirectoryFiles(char * name)
{
struct _finddata_t c_file;
long hFile;
char fstime[30]={0};
FsmFileInfoT info;
uint32 vfd;
FsmFileEnumT * tmp;
if(strncmp(name,VOLNAME,strlen(VOLNAME)) == 0)
{
memset(&info,0,sizeof(info));
// my_strlwr(name);
tmp = (FsmFileEnumT *)FsmFindFirstFile(name,&info);
if(tmp == NULL)
{
return 0;
}
vfd = tmp->vfd;
if(info.Attrib == 0)
{
FsmPrintf("\r\n%-25s%-20s%d\r",info.FileName,"<DIR>",info.CreateTime);
}
else
{
FsmPrintf("\r\n%-25s%-20d%d\r",info.FileName,info.FileLength,info.CreateTime);
}
while( FsmFindNextFile(tmp, &info) == 0 )
{
if(info.Attrib == 0)
{
FsmPrintf("\n%-25s%-20s%d\r",info.FileName,"<DIR>",info.CreateTime);
}
else
{
FsmPrintf("\n%-25s%-20d%d\r",info.FileName,info.FileLength,info.CreateTime);
}
}
FsmFindClose(tmp);
return 0;
}
/* Find first .c file in current directory */
if( (hFile = _findfirst( name, &c_file )) == -1L )
{
FsmPrintf("No files in current directory.\r\n" );
}
else
{
if(c_file.attrib & _A_SUBDIR)
{
FormatDirTime(c_file.time_write,fstime,0);
FsmPrintf("%-25s%-20s%s\r\n",c_file.name,"<DIR>",fstime);
}
else
{
FormatDirTime(c_file.time_write,fstime,0);
FsmPrintf("%-25s%-20d%s\r\n",c_file.name,c_file.size,fstime);
}
/* Find the rest of the .c files */
while( _findnext( hFile, &c_file ) == 0 )
{
if(c_file.attrib & _A_SUBDIR)
{
FormatDirTime(c_file.time_write,fstime,0);// wangli add for fstime
FsmPrintf("%-25s%-20s%s\r\n",c_file.name, "<DIR>",fstime);
}
else
{
FormatDirTime(c_file.time_write,fstime,0);
FsmPrintf("%-25s%-20d%s\r\n",c_file.name, c_file.size,fstime);
}
}
_findclose( hFile );
}
return 0;
}
int CMD_DIR(char s[],int pos[],int value[],int Segment)
{
if(Segment > 1)
DirectoryFiles(s+pos[1]);
else
DirectoryFiles("*.*");
return 0;
}
int GetLineFromFile(int FileHandle,char *s,int len)
{
uint8 c;
int i,j=0;
if (ReadAllFile(FileHandle,&c,1)<1) return 0;
len--;
for (i=0;i<len;)
{
j++;
if (c>=' ' || c==9) s[i++]=c;
if (c==10 || c==26)
break;
if (c==0)
{
s[i]=0;
if(i == 0) return i;
else return i+1;
}
if (ReadAllFile(FileHandle,&c,1)<1)
break;
}
s[i]=0;
return i+1;
}
int CMD_TYPE(char s[], int pos[], int value[], int Segment)
{
int FileHandle,len;
char t[1024];
FileHandle=OpenAllFile(s+pos[1],FSM_OPEN_READ | FSM_OPEN_EXISTING);
if (FileHandle <0)
{
FsmPrintf("\r\nSrcOpenError");
return 0;
}
while ((len=GetLineFromFile(FileHandle,t,sizeof(t))) != 0)
{
FsmPrintf("\r\n%s",t);
}
CloseAllFile(FileHandle);
return 0;
}
int Windows95cls(int color)
{
#ifdef WIN95
HANDLE h;
COORD p;
int x;
CONSOLE_SCREEN_BUFFER_INFO z;
h=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(h,&z);
p.X=0;
p.Y=0;
FillConsoleOutputCharacter(h,' ',z.dwSize.X*z.dwSize.Y,p,&x);
return 0;
#endif
}
int Windows95SetCursor(int x,int y)
{
#ifdef WIN95
HANDLE h;
COORD p;
h=GetStdHandle(STD_OUTPUT_HANDLE);
p.X=x;
p.Y=y;
SetConsoleCursorPosition(h,p);
return 0;
#endif
}
int CMD_CLS(char s[], int pos[], int value[], int Segment)
{
int i;
uint32 ThreadID;
ThreadID = GetCurrentThreadId();
for(i = 0; i < MAX_THREAD_NUM; i++)
{
if(ThreadID == system_data.TreadCtrl_t[i].ThreadID)
break;
}
if( i == MAX_THREAD_NUM)
{
return 0; //error
}
if(system_data.TreadCtrl_t[i].ThreadType == THREADTYPE_SOCKET)
{
FsmPrintf("\x1b[H\x1b[J");
return 0;
}
else
{
#ifdef WIN95
Windows95cls(0x07);
Windows95SetCursor(0,0);
#endif
}
return 0;
}
int CMD_RECLAIM(char s[], int pos[], int value[], int Segment)
{
// uint8 DevName[16];
char * DevName;
int i;
// memset(DevName,0,sizeof(DevName));
DevName = s+pos[1];
if(Segment == 2)
{
// strcpy(DevName,s+pos[1]);
// i = FsmDevFind(DevName);
i = FsmGetMatchedVolume(&DevName);
if(i < 0) return 0; //errocode
DfsReclaimProcess(Volume_Array[i].DevObjP);
}
return 0;
}
int CMD_DELETE(char s[], int pos[], int value[], int Segment)
{
uint8 FileName[MAX_PATH_LENGTH];
int i;
memset(FileName,0,sizeof(FileName));
if(Segment == 2)
{
strcpy(FileName,s+pos[1]);
i = FsmDevFind(FileName);
// if(i < 0) return 0; //errocode
DeleteAllFile(FileName);
}
return 0;
}
int RenameWinDowsFile(char* oldname,char* newname)
{
return rename(oldname,newname);
}
int RenameAllFile(char * oldname,char*newname)
{
if(strncmp(oldname,VOLNAME,strlen(VOLNAME)) == 0)
{
return FsmRename (oldname, newname);
}
else
return RenameWinDowsFile(oldname, newname);
}
int MakeAllDir(char * DirName)
{
if(strncmp(DirName,VOLNAME,strlen(VOLNAME)) == 0)
{
return FsmMakeDir(DirName);
}
else
{
return _mkdir(DirName);
}
}
int RemoveAllDir(char * DirName)
{
if(strncmp(DirName,VOLNAME,strlen(VOLNAME)) == 0)
{
return FsmRemoveDir(DirName);
}
else
{
return _rmdir(DirName);
}
}
int CMD_RENAME(char s[], int pos[], int value[], int Segment)
{
uint8 NewName[MAX_PATH_LENGTH];
uint8 OldName[MAX_PATH_LENGTH];
memset(NewName,0,sizeof(NewName));
memset(OldName,0,sizeof(OldName));
if(Segment == 3)
{
strncpy(OldName,s+pos[1],pos[2]-pos[1]);
strcpy(NewName,s+pos[2]);
RenameAllFile(OldName,NewName);
}
return 0;
}
int CMD_MD(char s[],int pos[],int value[],int Segment)
{
int i;
uint8 DirName[64][128];
memset(DirName,0,sizeof(DirName));
if (Segment<2)
{
return 0;
}
if(Segment > 64) Segment =64;
for (i=1;i<Segment;i++)
{
HighGetContentFromDoubleQuto(DirName[i-1],sizeof(DirName[i-1]),(s+pos[i]),(strlen(s+pos[i])+1));
if(MakeAllDir(DirName[i-1]) != 0)
{
FsmPrintf("\r\n\"%s: %s\";","CREATE_FAIL",DirName[i-1]);
}
else
{
FsmPrintf("\r\n\"%s: %s\";","CREATE_SUCCESS",DirName[i-1]);
}
}
return 0;
}
int CMD_RD(char s[],int pos[],int value[],int Segment)
{
int i;
uint8 DirName[64][128];
memset(DirName,0,sizeof(DirName));
if (Segment<2)
{
return 0;
}
if(Segment > 64) Segment=64;
for (i=1;i<Segment;i++)
{
HighGetContentFromDoubleQuto(DirName[i-1],sizeof(DirName[i-1]),(s+pos[i]),(strlen(s+pos[i])+1));
if(RemoveAllDir(DirName[i-1]) != 0)
{
FsmPrintf("\r\n\"%s: %s\";","DELETE_FAIL",DirName[i-1]);
}
else
{
FsmPrintf("\r\n\"%s: %s\";","DELETE_SUCCESS",DirName[i-1]);
}
}
return 0;
}
int CMD_GETFREESPACE(char s[],int pos[],int value[],int Segment)
{
uint8 VolName[VOLUME_NAME_LENGTH + 1];
uint32 TotalSpace;
uint32 AvailSpace;
uint32 FreeSpace;
if (Segment<2)
{
return 0;
}
if(strlen(s+pos[1]) > sizeof(VolName))
{
return 0;
}
strcpy(VolName,s+pos[1]);
FsmGetFreeSpace(VolName,&TotalSpace,&AvailSpace,&FreeSpace);
FsmPrintf("\r\nIn %s"
"\r\nTotal Space is \t\t0x%x,"
"\r\nAvailable Space is \t0x%x,"
"\r\nFree Space is \t\t0x%x",
VolName,TotalSpace,AvailSpace,FreeSpace);
return 0;
}
int CMD_MOUNTEDDEVSHOW(char s[], int pos[], int value[], int Segment)
{
int i;
if ( SEM_MTX_WAIT(VOLUME_Lock)!= ERR_NONE )
{
#ifdef FSM_DEBUG
FsmPrintf("VolumeLock semaphore fail!\n");
#endif
return VOLUME_NUMBER;
}
for ( i = 0; i < VOLUME_NUMBER; i++ )
{
if(Volume_Array[i].VolName[0] != 0)
{
FsmPrintf("\r\nDevName[%d]: %s",i,Volume_Array[i].VolName);
}
}
// Can Get Free Space here
SEM_MTX_POST(VOLUME_Lock);
return 0;
}
int CMD_HELP(char s[],int pos[],int value[],int Segment)
{
FsmPrintf("\r\nCLS, Clear Terminate Screen"
"\r\nQUIT, Quit This Terminate"
"\r\nVER, Print The Version of This Software"
"\r\nCOPY, Copy File, e.g. Copy SrcFile DestFile"
"\r\nTYPE, Type The File"
"\r\nRECLAIM, Activate Reclaimation Process"
"\r\nDELETE, Remove The File"
"\r\nMKDIR, Make New Dir"
"\r\nRMDIR, Remove The Dir"
"\r\nRENAME, Rename a File"
"\r\nVOLINFO, Get The Volume Space Info"
"\r\nDEVSHOW, Show Mounted Device Name in System"
"\r\nHELP, Help\r\n");
return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -