!133 feat: introduce mksh toybox to rootfs
Merge pull request !133 from MGY917/master
This commit is contained in:
@@ -111,14 +111,7 @@ INT32 ConsoleTcGetAttr(INT32 fd, struct termios *termios)
|
||||
struct file *filep = NULL;
|
||||
CONSOLE_CB *consoleCB = NULL;
|
||||
|
||||
if ((fd >= STDIN_FILENO) && (fd <= STDERR_FILENO)) {
|
||||
fd = ConsoleUpdateFd();
|
||||
if (fd < STDIN_FILENO) {
|
||||
return -EBADF;
|
||||
}
|
||||
}
|
||||
|
||||
int ret = fs_getfilep(fd, &filep);
|
||||
INT32 ret = fs_getfilep(fd, &filep);
|
||||
if (ret < 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
@@ -128,7 +121,7 @@ INT32 ConsoleTcGetAttr(INT32 fd, struct termios *termios)
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
termios->c_lflag = consoleCB->consoleTermios.c_lflag;
|
||||
(VOID)memcpy_s(termios, sizeof(struct termios), &consoleCB->consoleTermios, sizeof(struct termios));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -138,14 +131,8 @@ INT32 ConsoleTcSetAttr(INT32 fd, INT32 actions, const struct termios *termios)
|
||||
CONSOLE_CB *consoleCB = NULL;
|
||||
|
||||
(VOID)actions;
|
||||
if ((fd >= STDIN_FILENO) && (fd <= STDERR_FILENO)) {
|
||||
fd = ConsoleUpdateFd();
|
||||
if (fd < STDIN_FILENO) {
|
||||
return -EBADF;
|
||||
}
|
||||
}
|
||||
|
||||
int ret = fs_getfilep(fd, &filep);
|
||||
INT32 ret = fs_getfilep(fd, &filep);
|
||||
if (ret < 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
@@ -154,7 +141,8 @@ INT32 ConsoleTcSetAttr(INT32 fd, INT32 actions, const struct termios *termios)
|
||||
if (consoleCB == NULL) {
|
||||
return -EFAULT;
|
||||
}
|
||||
consoleCB->consoleTermios.c_lflag = termios->c_lflag;
|
||||
|
||||
(VOID)memcpy_s(&consoleCB->consoleTermios, sizeof(struct termios), termios, sizeof(struct termios));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -183,14 +171,13 @@ BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB)
|
||||
|
||||
STATIC INT32 ConsoleCtrlCaptureLine(CONSOLE_CB *consoleCB)
|
||||
{
|
||||
struct termios *consoleTermios = NULL;
|
||||
struct termios consoleTermios;
|
||||
UINT32 intSave;
|
||||
|
||||
LOS_SpinLockSave(&g_consoleSpin, &intSave);
|
||||
consoleTermios = &consoleCB->consoleTermios;
|
||||
(VOID)ConsoleTcGetAttr(consoleCB->fd, consoleTermios);
|
||||
consoleTermios->c_lflag |= ICANON | ECHO;
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, consoleTermios);
|
||||
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
|
||||
consoleTermios.c_lflag |= ICANON | ECHO;
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
|
||||
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
|
||||
|
||||
return LOS_OK;
|
||||
@@ -198,14 +185,13 @@ STATIC INT32 ConsoleCtrlCaptureLine(CONSOLE_CB *consoleCB)
|
||||
|
||||
STATIC INT32 ConsoleCtrlCaptureChar(CONSOLE_CB *consoleCB)
|
||||
{
|
||||
struct termios *consoleTermios = NULL;
|
||||
struct termios consoleTermios;
|
||||
UINT32 intSave;
|
||||
|
||||
LOS_SpinLockSave(&g_consoleSpin, &intSave);
|
||||
consoleTermios = &consoleCB->consoleTermios;
|
||||
(VOID)ConsoleTcGetAttr(consoleCB->fd, consoleTermios);
|
||||
consoleTermios->c_lflag &= ~(ICANON | ECHO);
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, consoleTermios);
|
||||
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
|
||||
consoleTermios.c_lflag &= ~(ICANON | ECHO);
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
|
||||
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
|
||||
|
||||
return LOS_OK;
|
||||
@@ -451,6 +437,20 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
|
||||
}
|
||||
}
|
||||
|
||||
VOID KillPgrp()
|
||||
{
|
||||
INT32 consoleId = -1;
|
||||
LosProcessCB *process = OsCurrProcessGet();
|
||||
|
||||
if ((process->consoleID > CONSOLE_NUM -1 ) || (process->consoleID < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
consoleId = process->consoleID;
|
||||
CONSOLE_CB *consoleCB = g_console[consoleId];
|
||||
(VOID)OsKillLock(consoleCB->pgrpId, SIGINT);
|
||||
}
|
||||
|
||||
STATIC INT32 UserFilepRead(CONSOLE_CB *consoleCB, struct file *filep, const struct file_operations_vfs *fops,
|
||||
CHAR *buffer, size_t bufLen)
|
||||
{
|
||||
@@ -829,6 +829,75 @@ ERROUT:
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
STATIC INT32 ConsoleSetSW(CONSOLE_CB *consoleCB, unsigned long arg)
|
||||
{
|
||||
struct termios kerTermios;
|
||||
UINT32 intSave;
|
||||
|
||||
if (LOS_ArchCopyFromUser(&kerTermios, (struct termios *)arg, sizeof(struct termios)) != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
LOS_SpinLockSave(&g_consoleSpin, &intSave);
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &kerTermios);
|
||||
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#define DEFAULT_WINDOW_SIZE_COL 80
|
||||
#define DEFAULT_WINDOW_SIZE_ROW 24
|
||||
STATIC INT32 ConsoleGetWinSize(unsigned long arg)
|
||||
{
|
||||
struct winsize kws = {
|
||||
.ws_col = DEFAULT_WINDOW_SIZE_COL,
|
||||
.ws_row = DEFAULT_WINDOW_SIZE_ROW
|
||||
};
|
||||
|
||||
if(LOS_ArchCopyToUser((VOID *)arg, &kws, sizeof(struct winsize)) != 0) {
|
||||
return -EFAULT;
|
||||
} else {
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INT32 ConsoleGetTermios(unsigned long arg)
|
||||
{
|
||||
struct file *filep = NULL;
|
||||
CONSOLE_CB *consoleCB = NULL;
|
||||
|
||||
INT32 ret = fs_getfilep(0, &filep);
|
||||
if (ret < 0) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
consoleCB = (CONSOLE_CB *)filep->f_priv;
|
||||
if (consoleCB == NULL) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if(LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) {
|
||||
return -EFAULT;
|
||||
} else {
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
INT32 ConsoleSetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
|
||||
{
|
||||
if (LOS_ArchCopyFromUser(&consoleCB->pgrpId, (INT32 *)(UINTPTR)arg, sizeof(INT32)) != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
INT32 ConsoleGetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
|
||||
{
|
||||
if (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->pgrpId, sizeof(INT32)) != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 ConsoleIoctl(struct file *filep, INT32 cmd, unsigned long arg)
|
||||
{
|
||||
INT32 ret;
|
||||
@@ -869,6 +938,21 @@ STATIC INT32 ConsoleIoctl(struct file *filep, INT32 cmd, unsigned long arg)
|
||||
case CONSOLE_CONTROL_REG_USERTASK:
|
||||
ret = ConsoleTaskReg(consoleCB->consoleID, arg);
|
||||
break;
|
||||
case TIOCGWINSZ:
|
||||
ret = ConsoleGetWinSize(arg);
|
||||
break;
|
||||
case TCSETSW:
|
||||
ret = ConsoleSetSW(consoleCB, arg);
|
||||
break;
|
||||
case TCGETS:
|
||||
ret = ConsoleGetTermios(arg);
|
||||
break;
|
||||
case TIOCGPGRP:
|
||||
ret = ConsoleGetPgrp(consoleCB, arg);
|
||||
break;
|
||||
case TIOCSPGRP:
|
||||
ret = ConsoleSetPgrp(consoleCB, arg);
|
||||
break;
|
||||
default:
|
||||
if ((cmd == UART_CFG_ATTR || cmd == UART_CFG_PRIVATE)
|
||||
&& !LOS_IsUserAddress(arg)) {
|
||||
@@ -940,6 +1024,7 @@ STATIC VOID OsConsoleTermiosInit(CONSOLE_CB *consoleCB, const CHAR *deviceName)
|
||||
/* set console to have a buffer for user */
|
||||
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
|
||||
consoleTermios.c_lflag |= ICANON | ECHO;
|
||||
consoleTermios.c_cc[VINTR] = 3; /* /003 for ^C */
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
|
||||
}
|
||||
#ifdef LOSCFG_NET_TELNET
|
||||
@@ -950,6 +1035,7 @@ STATIC VOID OsConsoleTermiosInit(CONSOLE_CB *consoleCB, const CHAR *deviceName)
|
||||
/* set console to have a buffer for user */
|
||||
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
|
||||
consoleTermios.c_lflag |= ICANON | ECHO;
|
||||
consoleTermios.c_cc[VINTR] = 3; /* /003 for ^C */
|
||||
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
|
||||
}
|
||||
#endif
|
||||
@@ -1165,6 +1251,7 @@ STATIC CONSOLE_CB *OsConsoleCBInit(UINT32 consoleID)
|
||||
(VOID)memset_s(consoleCB, sizeof(CONSOLE_CB), 0, sizeof(CONSOLE_CB));
|
||||
|
||||
consoleCB->consoleID = consoleID;
|
||||
consoleCB->pgrpId = -1;
|
||||
consoleCB->shellEntryId = SHELL_ENTRYID_INVALID; /* initialize shellEntryId to an invalid value */
|
||||
consoleCB->name = LOS_MemAlloc((VOID *)m_aucSysMem0, CONSOLE_NAMELEN);
|
||||
if (consoleCB->name == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user