Compare commits
18 Commits
OpenHarmon
...
OpenHarmon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89154a3765 | ||
|
|
8e6f3f1bfb | ||
|
|
d5c8341bb0 | ||
|
|
157fb8b212 | ||
|
|
95f7cf16d0 | ||
|
|
790573d018 | ||
|
|
246bdd11d8 | ||
|
|
017d8163ea | ||
|
|
f6d727fed8 | ||
|
|
a771e39988 | ||
|
|
594f50733e | ||
|
|
10bf30f91f | ||
|
|
60e77d0ea7 | ||
|
|
68b477588f | ||
|
|
2f8d12ece1 | ||
|
|
12d4bc05f4 | ||
|
|
b9d012b026 | ||
|
|
332ba8fd65 |
@@ -30,7 +30,7 @@
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
# common flags config
|
||||
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE $(LITEOS_GCOV_OPTS)
|
||||
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700 $(LITEOS_GCOV_OPTS)
|
||||
|
||||
ASFLAGS :=
|
||||
CFLAGS := $(LITEOS_COPTS) $(BASE_OPTS) -fPIE
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "unistd.h"
|
||||
#include "shcmd.h"
|
||||
|
||||
@@ -43,8 +43,13 @@ extern "C" {
|
||||
#define SHELL_ENTRY_STACKSIZE 0x1000
|
||||
#define SHELL_TASK_STACKSIZE 0x3000
|
||||
|
||||
#define SHELL_EXEC_COMMAND "exec "
|
||||
#define SHELL_EXEC_COMMAND_BYTES 5
|
||||
#define SHELL_EXEC_COMMAND "exec"
|
||||
#define SHELL_EXEC_COMMAND_BYTES 4
|
||||
#define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" "
|
||||
#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES+1)
|
||||
#define CMD_EXIT_COMMAND "exit"
|
||||
#define CMD_EXIT_COMMAND_BYTES 4
|
||||
#define CMD_EXIT_CODE_BASE_DEC 10
|
||||
|
||||
#define CONSOLE_IOC_MAGIC 'c'
|
||||
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
|
||||
@@ -57,6 +62,7 @@ extern "C" {
|
||||
typedef void (*OutputFunc)(const char *fmt, ...);
|
||||
extern int ShellTaskInit(ShellCB *shellCB);
|
||||
extern int ShellEntryInit(ShellCB *shellCB);
|
||||
extern void ChildExec(const char *cmdName, char *const paramArray[]);
|
||||
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
|
||||
extern int ShellNotify(ShellCB *shellCB);
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "show.h"
|
||||
#include "shmsg.h"
|
||||
#include "shcmd.h"
|
||||
@@ -95,6 +97,9 @@ static int DoShellExec(char **argv)
|
||||
int ret = SH_NOK;
|
||||
char *cmdLine = NULL;
|
||||
|
||||
if (strncmp(argv[0], SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
|
||||
ChildExec(argv[1], argv + 1);
|
||||
}
|
||||
for (i = 0; argv[i]; i++) {
|
||||
len += strlen(argv[i]);
|
||||
}
|
||||
@@ -121,7 +126,7 @@ int main(int argc, char **argv)
|
||||
int ret = SH_NOK;
|
||||
ShellCB *shellCB = NULL;
|
||||
|
||||
if (!strcmp(argv[0], "shell") && argv[1]) {
|
||||
if (argc > 1) {
|
||||
ret = DoShellExec(argv + 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "unistd.h"
|
||||
@@ -42,7 +44,10 @@
|
||||
#include "shell_pri.h"
|
||||
#include "shcmd.h"
|
||||
|
||||
#define CHAR_CTRL_C '\x03'
|
||||
#define CHAR_CTRL_DEL '\x7F'
|
||||
|
||||
#define VISIABLE_CHAR(ch) ((ch) > 0x1F && (ch) < 0x7F)
|
||||
|
||||
char *GetCmdline(ShellCB *shellCB)
|
||||
{
|
||||
@@ -200,7 +205,21 @@ void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
|
||||
}
|
||||
NOTIFY:
|
||||
outputFunc("\n");
|
||||
shellCB->shellBufOffset = 0;
|
||||
ShellTaskNotify(shellCB);
|
||||
}
|
||||
|
||||
void ParseCancelKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
|
||||
shellCB->shellBuf[0] = CHAR_CTRL_C;
|
||||
shellCB->shellBuf[1] = '\0';
|
||||
}
|
||||
|
||||
shellCB->shellBufOffset = 0;
|
||||
ShellTaskNotify(shellCB);
|
||||
}
|
||||
@@ -236,7 +255,7 @@ void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
|
||||
void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
if ((shellCB == NULL) || (outputFunc == NULL) || !VISIABLE_CHAR(ch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -254,7 +273,7 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
const char ch = c;
|
||||
int ret;
|
||||
|
||||
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
|
||||
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != CHAR_CTRL_C) && (ch != '\0')) {
|
||||
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
|
||||
}
|
||||
|
||||
@@ -263,8 +282,11 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
case '\n': /* enter */
|
||||
ParseEnterKey(outputFunc, shellCB);
|
||||
break;
|
||||
case CHAR_CTRL_C: /* ctrl + c */
|
||||
ParseCancelKey(outputFunc, shellCB);
|
||||
break;
|
||||
case '\b': /* backspace */
|
||||
case 0x7F: /* delete(0x7F) */
|
||||
case CHAR_CTRL_DEL: /* delete(0x7F) */
|
||||
ParseDeleteKey(outputFunc, shellCB);
|
||||
break;
|
||||
case '\t': /* tab */
|
||||
@@ -329,40 +351,80 @@ char *GetCmdName(const char *cmdline, unsigned int len)
|
||||
return cmdName;
|
||||
}
|
||||
|
||||
void ChildExec(const char *cmdName, char *const paramArray[])
|
||||
{
|
||||
int ret;
|
||||
pid_t gid;
|
||||
|
||||
ret = setpgrp();
|
||||
if (ret == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gid = getpgrp();
|
||||
if (gid < 0) {
|
||||
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
|
||||
}
|
||||
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
}
|
||||
|
||||
ret = execve(cmdName, paramArray, NULL);
|
||||
if (ret == -1) {
|
||||
perror("execve");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (strlen(cmdName) != CMD_EXIT_COMMAND_BYTES || strncmp(cmdName, CMD_EXIT_COMMAND, CMD_EXIT_COMMAND_BYTES) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmdParsed->paramCnt > 1) {
|
||||
printf("exit: too many arguments\n");
|
||||
return -1;
|
||||
}
|
||||
if (cmdParsed->paramCnt == 1) {
|
||||
char *p;
|
||||
ret = strtol(cmdParsed->paramArray[0], &p, CMD_EXIT_CODE_BASE_DEC);
|
||||
if (*p != '\0') {
|
||||
printf("exit: bad number: %s\n", cmdParsed->paramArray[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
|
||||
{
|
||||
int ret;
|
||||
pid_t forkPid;
|
||||
pid_t gid;
|
||||
|
||||
if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
|
||||
if (strncmp(cmdline, CMD_EXEC_COMMAND, CMD_EXEC_COMMAND_BYTES) == 0) {
|
||||
forkPid = fork();
|
||||
if (forkPid < 0) {
|
||||
printf("Faild to fork from shell\n");
|
||||
return;
|
||||
} else if (forkPid == 0) {
|
||||
ret = setpgrp();
|
||||
if (ret == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gid = getpgrp();
|
||||
if (gid < 0) {
|
||||
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
|
||||
}
|
||||
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray);
|
||||
} else {
|
||||
waitpid(forkPid, 0, 0);
|
||||
ret = tcsetpgrp(STDIN_FILENO, getpid());
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
}
|
||||
|
||||
ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
|
||||
if (ret == -1) {
|
||||
perror("execve");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (CheckExit(cmdName, cmdParsed) < 0) {
|
||||
return;
|
||||
}
|
||||
(void)syscall(__NR_shellexec, cmdName, cmdline);
|
||||
}
|
||||
}
|
||||
@@ -417,7 +479,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
|
||||
unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */
|
||||
unsigned int ret;
|
||||
char *newCmd = NULL;
|
||||
char *execCmd = SHELL_EXEC_COMMAND;
|
||||
char *execCmd = CMD_EXEC_COMMAND;
|
||||
const char *cmdBuf = input;
|
||||
unsigned int cmdBufLen = strlen(cmdBuf);
|
||||
char *shiftStr = (char *)malloc(cmdBufLen + 1);
|
||||
@@ -520,7 +582,11 @@ static void ShellCmdProcess(ShellCB *shellCB)
|
||||
if (buf == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf[0] == CHAR_CTRL_C) {
|
||||
printf("^C");
|
||||
buf[0] = '\n';
|
||||
}
|
||||
printf("\n");
|
||||
ExecCmdline(buf);
|
||||
ShellSaveHistoryCmd(buf, shellCB);
|
||||
shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;
|
||||
|
||||
59
bundle.json
Normal file
59
bundle.json
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "@ohos/kernel_liteos_a",
|
||||
"version": "",
|
||||
"description": "liteos-a内核",
|
||||
"homePage": "https://gitee.com/openharmony",
|
||||
"license": "BSD 3-clause",
|
||||
"repository": "https://gitee.com/openharmony/kernel_liteos_a",
|
||||
"domain": "os",
|
||||
"language": "",
|
||||
"publishAs": "code-segment",
|
||||
"private": false,
|
||||
"scripts": {},
|
||||
"tags": [
|
||||
"kernel"
|
||||
],
|
||||
"keywords": [
|
||||
"kernel",
|
||||
"liteos-a"
|
||||
],
|
||||
"envs": [],
|
||||
"dirs": [],
|
||||
"author": {
|
||||
"name": "",
|
||||
"email": "",
|
||||
"url": ""
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "",
|
||||
"email": "",
|
||||
"url": ""
|
||||
}
|
||||
],
|
||||
"segment": {
|
||||
"destPath": "kernel/liteos_a"
|
||||
},
|
||||
"component": {
|
||||
"name": "liteos-a",
|
||||
"subsystem": "liteos_a",
|
||||
"syscap": [
|
||||
"SystemCapability.Kernel.liteos-a"
|
||||
],
|
||||
"features": [],
|
||||
"adated_system_type": [
|
||||
"small"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [],
|
||||
"inner_kits": [],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,10 @@ extern "C" {
|
||||
#define DISK_ATA_GET_MODEL 21 /* Get model name */
|
||||
#define DISK_ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
#define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */
|
||||
#endif
|
||||
|
||||
typedef enum _disk_status_ {
|
||||
STAT_UNUSED,
|
||||
STAT_INUSED,
|
||||
@@ -187,6 +191,9 @@ typedef struct _los_disk_ {
|
||||
CHAR *disk_name;
|
||||
LOS_DL_LIST head; /* link head of all the partitions */
|
||||
struct pthread_mutex disk_mutex;
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
UINT8 *buff;
|
||||
#endif
|
||||
} los_disk;
|
||||
|
||||
typedef struct _los_part_ {
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
#include "sys/mount.h"
|
||||
#include "linux/spinlock.h"
|
||||
#include "path_cache.h"
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
#include "los_vm_common.h"
|
||||
#include "user_copy.h"
|
||||
#endif
|
||||
|
||||
los_disk g_sysDisk[SYS_MAX_DISK];
|
||||
los_part g_sysPart[SYS_MAX_PART];
|
||||
@@ -799,6 +803,78 @@ INT32 DiskPartitionRegister(los_disk *disk)
|
||||
return ENOERR;
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
static INT32 disk_read_directly(los_disk *disk, VOID *buf, UINT64 sector, UINT32 count)
|
||||
{
|
||||
INT32 result = VFS_ERROR;
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
if ((bops == NULL) || (bops->read == NULL)) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
|
||||
UINT32 cnt = 0;
|
||||
UINT8 *buffer = disk->buff;
|
||||
for (; count != 0; count -= cnt) {
|
||||
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
|
||||
result = bops->read(disk->dev, buffer, sector, cnt);
|
||||
if (result == (INT32)cnt) {
|
||||
result = ENOERR;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (LOS_CopyFromKernel(buf, disk->sector_size * cnt, buffer, disk->sector_size * cnt)) {
|
||||
result = VFS_ERROR;
|
||||
break;
|
||||
}
|
||||
buf = (UINT8 *)buf + disk->sector_size * cnt;
|
||||
sector += cnt;
|
||||
}
|
||||
} else {
|
||||
result = bops->read(disk->dev, buf, sector, count);
|
||||
if (result == count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static INT32 disk_write_directly(los_disk *disk, const VOID *buf, UINT64 sector, UINT32 count)
|
||||
{
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
INT32 result = VFS_ERROR;
|
||||
if ((bops == NULL) || (bops->read == NULL)) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
|
||||
UINT32 cnt = 0;
|
||||
UINT8 *buffer = disk->buff;
|
||||
for (; count != 0; count -= cnt) {
|
||||
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
|
||||
if (LOS_CopyToKernel(buffer, disk->sector_size * cnt, buf, disk->sector_size * cnt)) {
|
||||
result = VFS_ERROR;
|
||||
break;
|
||||
}
|
||||
result = bops->write(disk->dev, buffer, sector, cnt);
|
||||
if (result == (INT32)cnt) {
|
||||
result = ENOERR;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
buf = (UINT8 *)buf + disk->sector_size * cnt;
|
||||
sector += cnt;
|
||||
}
|
||||
} else {
|
||||
result = bops->write(disk->dev, buf, sector, count);
|
||||
if (result == count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
|
||||
{
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
@@ -837,21 +913,14 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL us
|
||||
PRINT_ERR("los_disk_read read err = %d, sector = %llu, len = %u\n", result, sector, len);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
result = VFS_ERROR;
|
||||
}
|
||||
#else
|
||||
if (disk->dev == NULL) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
if ((bops != NULL) && (bops->read != NULL)) {
|
||||
result = bops->read(disk->dev, (UINT8 *)buf, sector, count);
|
||||
if (result == (INT32)count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
}
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
}
|
||||
result = disk_read_directly(disk, buf, sector, count);
|
||||
#endif
|
||||
|
||||
if (result != ENOERR) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
@@ -900,18 +969,14 @@ INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count)
|
||||
PRINT_ERR("los_disk_write write err = %d, sector = %llu, len = %u\n", result, sector, len);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
|
||||
if ((bops != NULL) && (bops->write != NULL)) {
|
||||
result = bops->write(disk->dev, (UINT8 *)buf, sector, count);
|
||||
if (result == (INT32)count) {
|
||||
result = ENOERR;
|
||||
}
|
||||
result = VFS_ERROR;
|
||||
}
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
#else
|
||||
if (disk->dev == NULL) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
result = disk_write_directly(disk, buf, sector, count);
|
||||
#endif
|
||||
|
||||
if (result != ENOERR) {
|
||||
goto ERROR_HANDLE;
|
||||
}
|
||||
@@ -1153,7 +1218,8 @@ ERROR_HANDLE:
|
||||
|
||||
INT32 los_disk_cache_clear(INT32 drvID)
|
||||
{
|
||||
INT32 result;
|
||||
INT32 result = ENOERR;
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
los_part *part = get_part(drvID);
|
||||
los_disk *disk = NULL;
|
||||
|
||||
@@ -1161,7 +1227,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
result = OsSdSync(part->disk_id);
|
||||
if (result != 0) {
|
||||
if (result != ENOERR) {
|
||||
PRINTK("[ERROR]disk_cache_clear SD sync failed!\n");
|
||||
return result;
|
||||
}
|
||||
@@ -1174,7 +1240,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
|
||||
DISK_LOCK(&disk->disk_mutex);
|
||||
result = BcacheClearCache(disk->bcache);
|
||||
DISK_UNLOCK(&disk->disk_mutex);
|
||||
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1324,6 +1390,10 @@ static INT32 DiskDeinit(los_disk *disk)
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
DiskCacheDeinit(disk);
|
||||
#else
|
||||
if (disk->buff != NULL) {
|
||||
free(disk->buff);
|
||||
}
|
||||
#endif
|
||||
|
||||
disk->dev = NULL;
|
||||
@@ -1344,12 +1414,15 @@ static INT32 DiskDeinit(los_disk *disk)
|
||||
return ENOERR;
|
||||
}
|
||||
|
||||
static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
|
||||
struct geometry *diskInfo, struct Vnode *blkDriver)
|
||||
static UINT32 OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
|
||||
struct geometry *diskInfo, struct Vnode *blkDriver)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
OsBcache *bc = DiskCacheInit((UINT32)diskID, diskInfo, blkDriver);
|
||||
if (bc == NULL) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
disk->bcache = bc;
|
||||
#endif
|
||||
|
||||
@@ -1358,6 +1431,16 @@ static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
|
||||
(VOID)pthread_mutex_init(&disk->disk_mutex, &attr);
|
||||
|
||||
DiskStructInit(diskName, diskID, diskInfo, blkDriver, disk);
|
||||
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
disk->buff = malloc(diskInfo->geo_sectorsize * DISK_DIRECT_BUFFER_SIZE);
|
||||
if (disk->buff == NULL) {
|
||||
PRINT_ERR("OsDiskInitSub: direct buffer of disk init failed\n");
|
||||
return VFS_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ENOERR;
|
||||
}
|
||||
|
||||
INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
|
||||
@@ -1382,14 +1465,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
|
||||
ret = VnodeLookup(diskName, &blkDriver, 0);
|
||||
if (ret < 0) {
|
||||
VnodeDrop();
|
||||
PRINT_ERR("disk_init : find %s fail!\n", diskName);
|
||||
ret = ENOENT;
|
||||
goto DISK_FIND_ERROR;
|
||||
}
|
||||
struct block_operations *bops2 = (struct block_operations *)((struct drv_data *)blkDriver->data)->ops;
|
||||
|
||||
if ((bops2 == NULL) || (bops2->geometry == NULL) ||
|
||||
(bops2->geometry(blkDriver, &diskInfo) != 0)) {
|
||||
if ((bops2 == NULL) || (bops2->geometry == NULL) || (bops2->geometry(blkDriver, &diskInfo) != 0)) {
|
||||
goto DISK_BLKDRIVER_ERROR;
|
||||
}
|
||||
|
||||
@@ -1397,7 +1478,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
|
||||
goto DISK_BLKDRIVER_ERROR;
|
||||
}
|
||||
|
||||
OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
|
||||
ret = OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
|
||||
if (ret != ENOERR) {
|
||||
(VOID)DiskDeinit(disk);
|
||||
VnodeDrop();
|
||||
return VFS_ERROR;
|
||||
}
|
||||
VnodeDrop();
|
||||
if (DiskDivideAndPartitionRegister(info, disk) != ENOERR) {
|
||||
(VOID)DiskDeinit(disk);
|
||||
|
||||
@@ -2033,45 +2033,18 @@ static UINT get_oldest_time(DIR_FILE df[], DWORD *oldest_time, UINT len)
|
||||
return index;
|
||||
}
|
||||
|
||||
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
|
||||
static FRESULT fscheck(DIR *dp)
|
||||
{
|
||||
FATFS *fs = (FATFS *)vp->originMount->data;
|
||||
DIR_FILE df[CHECK_FILE_NUM] = {0};
|
||||
DIR *dp = NULL;
|
||||
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
|
||||
FILINFO fno;
|
||||
DWORD old_time = -1;
|
||||
DWORD time;
|
||||
UINT count;
|
||||
UINT index = 0;
|
||||
los_part *part = NULL;
|
||||
UINT count;
|
||||
DWORD time;
|
||||
DWORD old_time = -1;
|
||||
FRESULT result;
|
||||
int ret;
|
||||
|
||||
if (fs->fs_type != FS_FAT32) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((finfo->fattrib & AM_DIR) == 0) {
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
ret = fatfs_opendir(vp, dir);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
result = FR_TIMEOUT;
|
||||
goto ERROR_WITH_DIR;
|
||||
}
|
||||
|
||||
dp = (DIR *)dir->u.fs_dir;
|
||||
dp->obj.id = fs->id;
|
||||
for (count = 0; count < CHECK_FILE_NUM; count++) {
|
||||
if ((result = f_readdir(dp, &fno)) != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
return result;
|
||||
} else {
|
||||
if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
|
||||
break;
|
||||
@@ -2096,15 +2069,50 @@ int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
|
||||
index = get_oldest_time(df, &old_time, CHECK_FILE_NUM);
|
||||
}
|
||||
}
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
index = 0;
|
||||
while (result == FR_OK && index < count) {
|
||||
result = f_fcheckfat(&df[index]);
|
||||
++index;
|
||||
}
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
result = f_fcheckfat(&df[index]);
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
|
||||
{
|
||||
FATFS *fs = (FATFS *)vp->originMount->data;
|
||||
DIR *dp = NULL;
|
||||
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
los_part *part = NULL;
|
||||
#endif
|
||||
FRESULT result;
|
||||
int ret;
|
||||
|
||||
if (fs->fs_type != FS_FAT32) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((finfo->fattrib & AM_DIR) == 0) {
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
ret = fatfs_opendir(vp, dir);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
result = FR_TIMEOUT;
|
||||
goto ERROR_WITH_DIR;
|
||||
}
|
||||
|
||||
dp = (DIR *)dir->u.fs_dir;
|
||||
dp->obj.id = fs->id;
|
||||
result = fscheck(dp);
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
|
||||
unlock_fs(fs, FR_OK);
|
||||
|
||||
@@ -479,16 +479,6 @@ VOID LOS_PhysPagesFreeContiguous(VOID *ptr, size_t nPages)
|
||||
|
||||
VADDR_T *LOS_PaddrToKVaddr(PADDR_T paddr)
|
||||
{
|
||||
struct VmPhysSeg *seg = NULL;
|
||||
UINT32 segID;
|
||||
|
||||
for (segID = 0; segID < g_vmPhysSegNum; segID++) {
|
||||
seg = &g_vmPhysSeg[segID];
|
||||
if ((paddr >= seg->start) && (paddr < (seg->start + seg->size))) {
|
||||
return (VADDR_T *)(UINTPTR)(paddr - SYS_MEM_BASE + KERNEL_ASPACE_BASE);
|
||||
}
|
||||
}
|
||||
|
||||
return (VADDR_T *)(UINTPTR)(paddr - SYS_MEM_BASE + KERNEL_ASPACE_BASE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1568,7 +1568,7 @@ static void lwip_ping_usage(void)
|
||||
"\n ping [-n cnt] [-w interval] [-l data_len] destination"
|
||||
"\n ping [-t] [-w interval] destination"
|
||||
"\n ping -k");
|
||||
PRINTK("\n -t means ping forever, user can use -k to stop the forever ping");
|
||||
PRINTK("\n -t means ping forever, user can use -k to stop the forever ping\n");
|
||||
}
|
||||
|
||||
LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_len)
|
||||
|
||||
@@ -67,6 +67,9 @@ STATIC SPIN_LOCK_INIT(g_consoleSpin);
|
||||
#define CONSOLE_SEND_TASK_EXIT 0x04U
|
||||
#define CONSOLE_SEND_TASK_RUNNING 0x10U
|
||||
|
||||
#define SHELL_ENTRY_NAME "ShellEntry"
|
||||
#define SHELL_ENTRY_NAME_LEN 10
|
||||
|
||||
CONSOLE_CB *g_console[CONSOLE_NUM];
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
@@ -436,17 +439,16 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
|
||||
}
|
||||
}
|
||||
|
||||
VOID KillPgrp()
|
||||
VOID KillPgrp(UINT16 consoleId)
|
||||
{
|
||||
INT32 consoleId;
|
||||
LosProcessCB *process = OsCurrProcessGet();
|
||||
|
||||
if ((process->consoleID > CONSOLE_NUM - 1) || (process->consoleID < 0)) {
|
||||
if ((consoleId > CONSOLE_NUM) || (consoleId <= 0)) {
|
||||
return;
|
||||
}
|
||||
CONSOLE_CB *consoleCB = g_console[consoleId-1];
|
||||
/* the default of consoleCB->pgrpId is -1, may not be set yet, avoid killing all processes */
|
||||
if (consoleCB->pgrpId < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
consoleId = process->consoleID;
|
||||
CONSOLE_CB *consoleCB = g_console[consoleId];
|
||||
(VOID)OsKillLock(consoleCB->pgrpId, SIGINT);
|
||||
}
|
||||
|
||||
@@ -1443,15 +1445,31 @@ BOOL ConsoleEnable(VOID)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL IsShellEntryRunning(UINT32 shellEntryId)
|
||||
{
|
||||
LosTaskCB *taskCB;
|
||||
if (shellEntryId == SHELL_ENTRYID_INVALID) {
|
||||
return FALSE;
|
||||
}
|
||||
taskCB = OsGetTaskCB(shellEntryId);
|
||||
return !OsTaskIsUnused(taskCB) &&
|
||||
(strlen(taskCB->taskName) == SHELL_ENTRY_NAME_LEN &&
|
||||
strncmp(taskCB->taskName, SHELL_ENTRY_NAME, SHELL_ENTRY_NAME_LEN) == 0);
|
||||
}
|
||||
|
||||
INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID)
|
||||
{
|
||||
if (g_console[consoleID - 1]->shellEntryId == SHELL_ENTRYID_INVALID) {
|
||||
UINT32 intSave;
|
||||
|
||||
LOS_SpinLockSave(&g_consoleSpin, &intSave);
|
||||
if (!IsShellEntryRunning(g_console[consoleID - 1]->shellEntryId)) {
|
||||
g_console[consoleID - 1]->shellEntryId = taskID;
|
||||
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
|
||||
(VOID)OsSetCurrProcessGroupID(OsGetUserInitProcessID());
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
return LOS_NOK;
|
||||
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
|
||||
return g_console[consoleID - 1]->shellEntryId == taskID ? LOS_OK : LOS_NOK;
|
||||
}
|
||||
|
||||
BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB)
|
||||
|
||||
@@ -124,7 +124,7 @@ extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, cons
|
||||
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
|
||||
extern VOID OsWakeConsoleSendTask(VOID);
|
||||
#endif
|
||||
extern VOID KillPgrp(VOID);
|
||||
extern VOID KillPgrp(UINT16 consoleId);
|
||||
|
||||
/* console ioctl */
|
||||
#define CONSOLE_IOC_MAGIC 'c'
|
||||
|
||||
@@ -238,7 +238,7 @@ static void HiLogHeadInit(struct HiLogEntry *header, size_t len)
|
||||
|
||||
ret = clock_gettime(CLOCK_REALTIME, &now);
|
||||
if (ret != 0) {
|
||||
dprintf("In %s line %d,clock_gettime fail", __FUNCTION__, __LINE__);
|
||||
dprintf("In %s line %d,clock_gettime fail\n", __FUNCTION__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -255,7 +255,9 @@ static void HiLogCoverOldLog(size_t bufLen)
|
||||
int retval;
|
||||
struct HiLogEntry header;
|
||||
size_t totalSize = bufLen + sizeof(struct HiLogEntry);
|
||||
int dropLogLines = 0;
|
||||
static int dropLogLines = 0;
|
||||
static int isLastTimeFull = 0;
|
||||
int isThisTimeFull = 0;
|
||||
|
||||
while (totalSize + g_hiLogDev.size > HILOG_BUFFER) {
|
||||
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
|
||||
@@ -264,11 +266,18 @@ static void HiLogCoverOldLog(size_t bufLen)
|
||||
}
|
||||
|
||||
dropLogLines++;
|
||||
isThisTimeFull = 1;
|
||||
isLastTimeFull = 1;
|
||||
HiLogBufferDec(sizeof(header));
|
||||
HiLogBufferDec(header.len);
|
||||
}
|
||||
if (dropLogLines > 0) {
|
||||
dprintf("hilog ringbuffer full, drop %d line(s) log", dropLogLines);
|
||||
if (isLastTimeFull == 1 && isThisTimeFull == 0) {
|
||||
/* so we can only print one log if hilog ring buffer is full in a short time */
|
||||
if (dropLogLines > 0) {
|
||||
dprintf("hilog ringbuffer full, drop %d line(s) log\n", dropLogLines);
|
||||
}
|
||||
isLastTimeFull = 0;
|
||||
dropLogLines = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +339,7 @@ static void HiLogDeviceInit(void)
|
||||
{
|
||||
g_hiLogDev.buffer = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, HILOG_BUFFER);
|
||||
if (g_hiLogDev.buffer == NULL) {
|
||||
dprintf("In %s line %d,LOS_MemAlloc fail", __FUNCTION__, __LINE__);
|
||||
dprintf("In %s line %d,LOS_MemAlloc fail\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
init_waitqueue_head(&g_hiLogDev.wq);
|
||||
|
||||
@@ -118,14 +118,14 @@ STATIC VOID OsMagicMemCheck(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
INT32 CheckMagicKey(CHAR key)
|
||||
INT32 CheckMagicKey(CHAR key, UINT16 consoleId)
|
||||
{
|
||||
#ifdef LOSCFG_ENABLE_MAGICKEY
|
||||
INT32 i;
|
||||
STATIC UINT32 magicKeySwitch = 0;
|
||||
|
||||
if (key == 0x03) { /* ctrl + c */
|
||||
KillPgrp();
|
||||
KillPgrp(consoleId);
|
||||
return 0;
|
||||
} else if (key == 0x12) { /* ctrl + r */
|
||||
magicKeySwitch = ~magicKeySwitch;
|
||||
|
||||
@@ -46,7 +46,7 @@ typedef struct {
|
||||
CHAR magicKey;
|
||||
} MagicKeyOp;
|
||||
|
||||
extern INT32 CheckMagicKey(CHAR key);
|
||||
extern INT32 CheckMagicKey(CHAR key, UINT16 consoleId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "los_excinfo_pri.h"
|
||||
#endif
|
||||
#include "los_exc_pri.h"
|
||||
|
||||
#include "los_sched_pri.h"
|
||||
|
||||
#define SIZEBUF 256
|
||||
|
||||
@@ -94,7 +94,7 @@ STATIC VOID ConsoleOutput(const CHAR *str, UINT32 len)
|
||||
|
||||
for (;;) {
|
||||
cnt = write(STDOUT_FILENO, str + writen, (size_t)toWrite);
|
||||
if ((cnt < 0) || (toWrite == cnt)) {
|
||||
if ((cnt < 0) || ((cnt == 0) && ((!OsPreemptable()) || (OS_INT_ACTIVE))) || (toWrite == cnt)) {
|
||||
break;
|
||||
}
|
||||
writen += cnt;
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
|
||||
#include "shcmd.h"
|
||||
|
||||
#define DEFAULT_SCREEN_WIDTH 80
|
||||
#define MAX_CMD_KEY_WIDTH 12
|
||||
#define CMD_ITEM_PER_LINE (DEFAULT_SCREEN_WIDTH / (MAX_CMD_KEY_WIDTH + 1))
|
||||
|
||||
UINT32 OsShellCmdHelp(UINT32 argc, const CHAR **argv)
|
||||
{
|
||||
UINT32 loop = 0;
|
||||
@@ -45,15 +49,16 @@ UINT32 OsShellCmdHelp(UINT32 argc, const CHAR **argv)
|
||||
|
||||
PRINTK("*******************shell commands:*************************\n");
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(curCmdItem, &(cmdInfo->cmdList.list), CmdItemNode, list) {
|
||||
if ((loop & (8 - 1)) == 0) { /* 8 - 1:just align print */
|
||||
if ((loop % CMD_ITEM_PER_LINE) == 0) { /* just align print */
|
||||
PRINTK("\n");
|
||||
}
|
||||
PRINTK("%-12s ", curCmdItem->cmd->cmdKey);
|
||||
PRINTK("%-12s ", curCmdItem->cmd->cmdKey);
|
||||
|
||||
loop++;
|
||||
}
|
||||
|
||||
PRINTK("\n");
|
||||
PRINTK("\n\nAfter shell prompt \"OHOS # \":\n"
|
||||
"Use `<cmd> [args ...]` to run built-in shell commands listed above.\n"
|
||||
"Use `exec <cmd> [args ...]` or `./<cmd> [args ...]` to run external commands.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,10 @@ static int GetFullpathNull(int fd, const char *path, char **filePath)
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
fullPath = file->f_path;
|
||||
fullPath = strdup(file->f_path);
|
||||
if (fullPath == NULL) {
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
} else {
|
||||
ret = GetFullpath(fd, path, &fullPath);
|
||||
if (ret < 0) {
|
||||
|
||||
Reference in New Issue
Block a user