149 lines
3.5 KiB
C
Executable File
149 lines
3.5 KiB
C
Executable File
#include <stdio.h>
|
|
#include "GxStrg.h"
|
|
#include "GxStrgInt.h"
|
|
#include "uToken.h"
|
|
#include "NvtUctrlAPI.h"
|
|
#include "SxCmd.h"
|
|
|
|
#define UGXSTRG_STR_READY "ready"
|
|
#define UGXSTRG_STR_UNFMT "unfmt"
|
|
#define UGXSTRG_STR_NODEV "nodev"
|
|
|
|
#define GXSTRG_SXCMD_TEST 0
|
|
|
|
//GXSTRG_LINUX_STATUS g_LnxStrgStatus[GXSTRG_STRG_NUM] = {0};
|
|
|
|
static UTOKEN_INT32 GxStrg_UCtrl_status(UTOKEN_INT32 argc, UTOKEN_CHAR *argv[])
|
|
{
|
|
char *pMntStatus = NULL;
|
|
char *pMntName = NULL;
|
|
char *pDrvName = NULL;
|
|
UINT32 DevId;
|
|
UINT32 StrgCbVal;
|
|
BOOL bIsReadOnly = FALSE;
|
|
BOOL bIsFormatted;
|
|
|
|
if (argc < 3) {
|
|
DBG_ERR("argc(%d) < 3\r\n", argc);
|
|
return -1;
|
|
}
|
|
|
|
//default necessary arguments
|
|
pMntStatus = argv[0];
|
|
pMntName = argv[1];
|
|
pDrvName = argv[2];
|
|
|
|
//optional arguments
|
|
if (argc > 3) {
|
|
bIsReadOnly = (BOOL)atoi(argv[3]);
|
|
}
|
|
|
|
DBG_IND("MntStatus %s, MntName %s, DrvName %s, IsReadOnly %d\r\n", pMntStatus, pMntName, pDrvName, bIsReadOnly);
|
|
|
|
if (0 == strcmp(pMntStatus, UGXSTRG_STR_READY)) {
|
|
StrgCbVal = STRG_CB_INSERTED;
|
|
bIsFormatted = TRUE;
|
|
} else if (0 == strcmp(pMntStatus, UGXSTRG_STR_NODEV)) {
|
|
StrgCbVal = STRG_CB_REMOVED;
|
|
bIsFormatted = FALSE;
|
|
} else if (0 == strcmp(pMntStatus, UGXSTRG_STR_UNFMT)) {
|
|
StrgCbVal = STRG_CB_INSERTED;
|
|
bIsFormatted = FALSE;
|
|
} else {
|
|
DBG_ERR("Unknown MntStatus %s\r\n", pMntStatus);
|
|
return -1;
|
|
}
|
|
DBG_IND("StrgCbVal %d\r\n", StrgCbVal);
|
|
|
|
if (pDrvName[0] < GXSTRG_DRVNAME_FIRST || pDrvName[0] > GXSTRG_DRVNAME_LAST) {
|
|
DBG_ERR("Invalid drv name %c\r\n", pDrvName[0]);
|
|
return -1;
|
|
}
|
|
DevId = pDrvName[0] - GXSTRG_DRVNAME_FIRST;
|
|
DBG_IND("DevId %d\r\n", DevId);
|
|
|
|
snprintf(g_FSInitParam[DevId].FSParam.szMountPath, sizeof(g_FSInitParam[DevId].FSParam.szMountPath), "/mnt/%s", pMntName);
|
|
g_LnxStrgStatus[DevId].IsInserted = (StrgCbVal == STRG_CB_INSERTED);
|
|
g_LnxStrgStatus[DevId].IsReadOnly = bIsReadOnly;
|
|
g_LnxStrgStatus[DevId].IsFormatted = bIsFormatted;
|
|
|
|
DBG_DUMP("MntPath %s, IsInserted %d, IsReadOnly %d, bIsFormatted %d\r\n",
|
|
g_FSInitParam[DevId].FSParam.szMountPath,
|
|
g_LnxStrgStatus[DevId].IsInserted,
|
|
g_LnxStrgStatus[DevId].IsReadOnly,
|
|
g_LnxStrgStatus[DevId].IsFormatted);
|
|
|
|
if (g_fpStrgCB) {
|
|
(*g_fpStrgCB)(StrgCbVal, DevId, 0);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static UTOKEN_INT32 GxStrg_UCtrl_begin(UTOKEN_CHAR *str, UTOKEN_INT32 len)
|
|
{
|
|
DBG_IND("%s\r\n", str);
|
|
return 0;
|
|
}
|
|
|
|
static UTOKEN_INT32 GxStrg_UCtrl_end(UTOKEN_END_INFO *p_info)
|
|
{
|
|
char retStr[64] = {0};
|
|
|
|
if (p_info->err_code < 0) {
|
|
snprintf(retStr, sizeof(retStr), "ERR: parm %s", p_info->failed_name);
|
|
|
|
if (NVTUCTRL_RET_OK == NvtUctrl_SetRetString(retStr)) {
|
|
DBG_ERR("%s\r\n", retStr);
|
|
}
|
|
|
|
return p_info->err_code;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static UTOKEN_INT32 GxStrg_UCtrl_unknown(UTOKEN_CHAR *name)
|
|
{
|
|
DBG_ERR("unknown argument: %s\r\n", name);
|
|
return 0;
|
|
}
|
|
|
|
UTOKEN_PARAM tbl_gxstrg_param[] = {
|
|
{"status", GxStrg_UCtrl_status},
|
|
{NULL, NULL}, //last tag, it must be
|
|
};
|
|
|
|
UTOKEN_MODULE module_gxstrg = {
|
|
"gxstrg",
|
|
tbl_gxstrg_param,
|
|
GxStrg_UCtrl_begin,
|
|
GxStrg_UCtrl_end,
|
|
GxStrg_UCtrl_unknown,
|
|
NULL
|
|
};
|
|
|
|
#if GXSTRG_SXCMD_TEST
|
|
//to test GxStrg with UCtrl:
|
|
//1. set GXSTRG_SXCMD_TEST to 1
|
|
//2. extern GxStrg_InstallCmd() and call this function
|
|
//3. type SxCmd to test. e.g. (gxstrg uctrl -status mounted sd A 0)
|
|
void GxStrg_InstallCmd(void);
|
|
|
|
static BOOL Cmd_GxStrg_uctrl(CHAR *strCmd)
|
|
{
|
|
uToken_Parse(strCmd, &module_gxstrg);
|
|
return TRUE;
|
|
}
|
|
|
|
SXCMD_BEGIN(gxstrg, "GxStrg")
|
|
SXCMD_ITEM("uctrl %", Cmd_GxStrg_uctrl, "")
|
|
SXCMD_END()
|
|
|
|
void GxStrg_InstallCmd(void)
|
|
{
|
|
SxCmd_AddTable(gxstrg);
|
|
}
|
|
#endif
|
|
|