1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "los_memory.h"
17 #include "shcmd.h"
18 #include "show.h"
19
OsShellCmdMount(int argc,const char ** argv)20 int OsShellCmdMount(int argc, const char **argv)
21 {
22 int ret = 0;
23
24 if (argc < 3) {
25 PRINT_ERR("Usage: mount [DEVICE] [PATH] [FSTYPE]\n");
26 return -1;
27 }
28
29 int strLen = strlen("/dev/cfiblk");
30 if (strncmp(argv[0], "/dev/cfiblk", strLen)) {
31 PRINT_ERR("mount can not found this device [%s], [/dev/cfiblk] support only now\n", argv[0]);
32 return -1;
33 }
34
35 strLen = strlen(argv[2]);
36 if ((strncmp(argv[2], "fat", strLen) && strncmp(argv[2], "FAT", strLen)) || strLen != strlen("fat")) {
37 PRINT_ERR("mount do not support this fstype [%s] now, try 'fat'\n", argv[2]);
38 return -1;
39 }
40
41 if (ret = mount(argv[1], argv[1], argv[2], 0, NULL)) {
42 PRINT_ERR("Mount error:%d\n", ret);
43 return -1;
44 }
45
46 return 0;
47 }
48
49 CmdItem g_shellcmd[] = {
50 {CMD_TYPE_EX, "mount", XARGS, (CmdCallBackFunc)OsShellCmdMount},
51 };
52
MountShellInit(void)53 void MountShellInit(void)
54 {
55 UINT8 *cmdItemGroup = NULL;
56 CmdItemNode *cmdItem = NULL;
57
58 OsShellInit();
59 CmdModInfo *cmdInfo = OsCmdInfoGet();
60
61 cmdItemGroup = (UINT8 *)LOS_MemAlloc(m_aucSysMem0, sizeof(CmdItemNode));
62 if (cmdItemGroup == NULL) {
63 PRINT_ERR("MountShellInit error ...\n");
64 return;
65 }
66
67 cmdItem = (CmdItemNode *)cmdItemGroup;
68 cmdItem->cmd = &g_shellcmd[0];
69 OsCmdAscendingInsert(cmdItem);
70 cmdInfo->listNum += 1;
71
72 if (DiscDrvInit()) {
73 PRINT_ERR("SetupDiscDrv error\n");
74 }
75 }
76