📄 filesystemcomtrol.c
字号:
///////////////////////////////////////////////////////////////////////////////
//
// File name: MassStorage.C
// Version: 1.0
// Date: 2003/7/13
// Description: MSCD=>Mass Storage Class Driver
//
//
// Author:
// Email:
// Phone: (03) 578-7888
// Company: Faraday Tech. Corp.
///////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "chipset.h"
#include "flib.h"
#include "Lib_Host20.h"
#include "Host20_AP.H"
#include "scsi.h"
#include "FileSystemComtrol.H"
#include "command.h"
#include "filectrl.h"
//#include "serial.h"
UINT8 bQuit = 0;
extern UINT32 USB_SectorReadCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_SectorWriteCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_DirCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_ChangeDirCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_MakeCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_DeleteCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_RenameCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_CopyCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_CmpCmd(CommandTableStruct_T *CmdTable);
extern UINT32 USB_OpCmd(CommandTableStruct_T *CmdTable);
extern UINT32 CurrentDrive;
CommandTableStruct_T UsbDisk_CmdTable[] =
{
{{"sr", NULL,}, "sr sector_num sector_count\n",
0, 0, 2, 2, 0, 0, USB_SectorReadCmd, 0, 0,
{
{IS_NUM|IS_USER_SYMBOL, NULL, 0, FALSE, "sector_num - which sector to read\n"},
{IS_NUM|IS_USER_SYMBOL, NULL, 0, FALSE, "sector_count - number of sectors to read\n"},
},
},
{{"sw", NULL,}, "sw pattern sector_num sector_count\n",
0, 0, 3, 3, 0, 0, USB_SectorWriteCmd, 0, 0,
{
{IS_NUM|IS_USER_SYMBOL, NULL, 0, FALSE, "pattern - data to write\n"},
{IS_NUM|IS_USER_SYMBOL, NULL, 0, FALSE, "sector_num - which sector to write\n"},
{IS_NUM|IS_USER_SYMBOL, NULL, 0, FALSE, "sector_count - number of sectors to write\n"},
},
},
{{"dir", NULL,}, "dir [directory/file]\n",
0, 0, 1, 0, 0, 0, USB_DirCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "[directory/file] - directory or file\n"},
},
},
{{"cd", NULL,}, "cd [directory]\n",
0, 0, 1, 1, 0, 0, USB_ChangeDirCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "[directory] - directory\n"},
},
},
{{"mk", NULL,}, "mk [name] [-d]\n",
0, 0, 1, 1, 1, 0, USB_MakeCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "[name] - file or directory name\n"},
},
{
{"-d", IS_NULL, {NULL,}, NULL, 0, FALSE, "[-d] - [name] is directory\n"},
},
},
{{"remove", "del", NULL,}, "remove/del [name] [-d]\n",
0, 0, 1, 1, 1, 0, USB_DeleteCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "[name] - file or directory name\n"},
},
{
{"-d", IS_NULL, {NULL,}, NULL, 0, FALSE, "[-d] - [name] is directory\n"},
},
},
{{"rename", "ren", NULL,}, "rename/ren old_name new_name\n",
0, 0, 2, 2, 0, 0, USB_RenameCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "old_name -\n"}, {IS_STR, NULL, 0, FALSE, "new_name -\n"},
},
},
{{"copy", "cp", NULL,}, "copy/cp src_file dst_file\n",
0, 0, 2, 2, 0, 0, USB_CopyCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "src_file -\n"}, {IS_STR, NULL, 0, FALSE, "dst_file -\n"},
},
},
{{"compare", "cmp", NULL,}, "copy/cmp src_file dst_file\n",
0, 0, 2, 2, 0, 0, USB_CmpCmd, 0, 0,
{
{IS_STR, NULL, 0, FALSE, "src_file -\n"}, {IS_STR, NULL, 0, FALSE, "dst_file -\n"},
},
},
{{"op", NULL,}, "op [Item]\n",
0, 0, 1, 1, 0, 0, USB_OpCmd, 0, 0,
{
{IS_NUM, NULL, 0, FALSE, "[Item] - OP items or commands 0: Role Change 1: Quit\n"},
},
},
{NULL,
},
};
//===============================================================================================
//===============================================================================================
//===============================================================================================
//============================= Group-1: File System Command Implement ==========================
//===============================================================================================
//===============================================================================================
//===============================================================================================
//***************************************************************************************
// Function Name:
// Description:
// Input:
// Output:
// Status:
//***************************************************************************************
UINT32 USB_SectorReadCmd(CommandTableStruct_T *CmdTable)
{
INT8 Buf[0x800];
int i;
// Before execut any command, must do these SCSI check.
bSCSI_TEST_UNIT_READY();
//john mark for stall bSCSI_MODE_SENSE();
if(!bSCSI_READ_10(&(Mass_stor_us->Mass_stor_device[u8Drive]),CmdTable->Argu[0].Value, CmdTable->Argu[1].Value,
Mass_stor_us->Mass_stor_device[u8Drive].u32BlockSize, Buf))
{
printk("read error!!!\n");
// return ERROR_COMMAND;
}
else
printk("\nread OK!!!\n");
#if 1
for(i = 0; i < 512 * CmdTable->Argu[1].Value; i++)
{
if((i % 16) == 0)
printk("\n%0.4X ", i);
printk("%0.2X ", Buf[i]);
}
#endif
return OK_COMMAND;
}
//***************************************************************************************
// Function Name:
// Description:
// Input:
// Output:
// Status:
//***************************************************************************************
UINT32 USB_SectorWriteCmd(CommandTableStruct_T *CmdTable)
{
INT8 Buf[0x800];
int i;
for(i = 0; i < 512;i++)
Buf[i] = CmdTable->Argu[0].Value + i;
// Before execut any command, must do these SCSI check.
bSCSI_TEST_UNIT_READY();
// john mark for stall bSCSI_MODE_SENSE();
if(!bSCSI_Write_10(&(Mass_stor_us->Mass_stor_device[u8Drive]), CmdTable->Argu[1].Value, CmdTable->Argu[2].Value,
Mass_stor_us->Mass_stor_device[u8Drive].u32BlockSize, Buf))
{
printk("Write error!!!\n");
return ERROR_COMMAND;
}
else
printk("Write OK!!!\n");
return OK_COMMAND;
}
//***************************************************************************************
// Function Name:
// Description:
// Input:
// Output:
// Status:
//***************************************************************************************
UINT32 USB_DirCmd(CommandTableStruct_T *CmdTable)
{
UINT8* MsgStr;
UINT32 u32DirEntrySave = NULL, u32FileCount = 0;
MsgStr = (UINT8*)malloc(0x100);
// Change u8Drive to Drive whitch we want to operate, and do SCSI command check,
// This check is important.
vScsi_Device_Check(CmdTable->Argu[0].Str);
#if 0
if(!fLib_DirDirectory((CmdTable->Argu[0].IsSet ? CmdTable->Argu[0].Str : NULL), MsgStr))
{
u8Drive = CurrentDrive;
return ERROR_COMMAND;
}
printk(MsgStr);
#else
do
{
if((u32DirEntrySave = fLib_DirDirectoryEx((CmdTable->Argu[0].IsSet ? CmdTable->Argu[0].Str : NULL),
MsgStr,0x100,u32DirEntrySave,&u32FileCount)) == 0xFFFFFFFF)
{
u8Drive = CurrentDrive;
return ERROR_COMMAND;
}
printk(MsgStr);
memset(MsgStr,0,sizeof(MsgStr));
}while(u32DirEntrySave != NULL);
printk("<<%d files in this directory>>\n",u32FileCount);
#endif
u8Drive = CurrentDrive;
free(MsgStr);
return OK_COMMAND;
}
//***************************************************************************************
// Function Name:
// Description:
// Input:
// Output:
// Status:
//***************************************************************************************
UINT32 USB_ChangeDirCmd(CommandTableStruct_T *CmdTable)
{
// Change u8Drive to Drive whitch we want to operate, and do SCSI command check,
// This check is important.
if ( *(CmdTable->Argu[0].Str) != 's' )
vScsi_Device_Check(CmdTable->Argu[0].Str);
else
printk("Change to loca directory\n");
if(fLib_ChangeDirectory(CmdTable->Argu[0].Str))
{
printk("Change to %s directory OK!!!\n", CmdTable->Argu[0].Str);
return OK_COMMAND;
}
else
{
printk("Change to %s directory error!!!\n", CmdTable->Argu[0].Str);
u8Drive = CurrentDrive;
}
return ERROR_COMMAND;
}
//***************************************************************************************
// Function Name:
// Description:
// Input:
// Output:
// Status:
//***************************************************************************************
UINT32 USB_MakeCmd(CommandTableStruct_T *CmdTable)
{
// Change u8Drive to Drive whitch we want to operate, and do SCSI command check,
// This check is important.
vScsi_Device_Check(CmdTable->Argu[0].Str);
if(CmdTable->Opt[0].IsSet)
{
if(fLib_MakeDirectory(CmdTable->Argu[0].Str))
{
printk("Make %s directory OK!!!\n", CmdTable->Argu[0].Str);
u8Drive = CurrentDrive;
return OK_COMMAND;
}
}
else
{
if(fLib_MakeEmptyFile(CmdTable->Argu[0].Str))
{
printk("Make %s file OK!!!\n", CmdTable->Argu[0].Str);
u8Drive = CurrentDrive;
return OK_COMMAND;
}
}
printk("Make %s file or directory error!!!\n", CmdTable->Argu[0].Str);
u8Drive = CurrentDrive;
return ERROR_COMMAND;
}
//***************************************************************************************
// Function Name:
// Description:
// Input:
// Output:
// Status:
//***************************************************************************************
UINT32 USB_DeleteCmd(CommandTableStruct_T *CmdTable)
{
// Change u8Drive to Drive whitch we want to operate, and do SCSI command check,
// This check is important.
vScsi_Device_Check(CmdTable->Argu[0].Str);
if(CmdTable->Opt[0].IsSet)
{
if(fLib_DeleteDirectory(CmdTable->Argu[0].Str))
{
printk("Del %s directory OK!!!\n", CmdTable->Argu[0].Str);
u8Drive = CurrentDrive;
return OK_COMMAND;
}
}
else
{
if(remove(CmdTable->Argu[0].Str) != -1)
{
printk("Del %s file OK!!!\n", CmdTable->Argu[0].Str);
u8Drive = CurrentDrive;
return OK_COMMAND;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -