更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
disk_shellcmd.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "stdio.h"
33#include "stdlib.h"
34#include "los_config.h"
35#ifdef LOSCFG_SHELL_CMD_DEBUG
36#include "disk.h"
37#include "shcmd.h"
38#include "shell.h"
39#include "path_cache.h"
40/*
41* partinfo命令用于查看系统识别的硬盘,SD卡多分区信息
42* 参数 参数说明 取值范围
43* dev_inodename 要查看的分区名字 合法的分区名
44
45* 使用实例: partinfo /dev/mmcblk0p0
46* 输出说明
47OHOS # partinfo /dev/mmcblk0p0
48
49partinfo:
50disk_id : 0
51part_id in system : 0
52part no in disk : 0
53part no in mbr : 1
54part filesystem : 0C
55part dev name : mmcblk0p0
56part sec start : 8192
57part sec count : 31108096
58*/
60{
61 struct Vnode *node = NULL;
62 los_part *part = NULL;
63 const CHAR *str = "/dev";
64 int ret;
65
66 if ((argc != 1) || (strncmp(argv[0], str, strlen(str)) != 0)) {//参数必须是 /dev 开头
67 PRINTK("Usage :\n");
68 PRINTK(" partinfo <dev_vnodename>\n");
69 PRINTK(" dev_vnodename : the name of dev\n");
70 PRINTK("Example:\n");
71 PRINTK(" partinfo /dev/sdap0 \n");
72
73 set_errno(EINVAL);
74 return -LOS_NOK;
75 }
76 VnodeHold();
77 ret = VnodeLookup(argv[0], &node, 0);//通过设备名称找到索引节点
78 if (ret < 0) {
79 PRINT_ERR("no part found\n");
80 VnodeDrop();
81 set_errno(ENOENT);
82 return -LOS_NOK;
83 }
84
85 part = los_part_find(node);//通过索引节点找到分区信息
86 VnodeDrop();
87 show_part(part);
88
89 return LOS_OK;
90}
91
92SHELLCMD_ENTRY(partinfo_shellcmd, CMD_TYPE_EX, "partinfo", XARGS, (CmdCallBackFunc)osShellCmdPartInfo);
93
94#endif
@ CMD_TYPE_EX
不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。
Definition: shell.h:91
INT32 osShellCmdPartInfo(INT32 argc, const CHAR **argv)
Definition: disk_shellcmd.c:59
SHELLCMD_ENTRY(partinfo_shellcmd, CMD_TYPE_EX, "partinfo", XARGS,(CmdCallBackFunc) osShellCmdPartInfo)
VOID show_part(los_part *part)
Print partition information.
Definition: disk.c:1810
los_part * los_part_find(struct Vnode *blkDriver)
Find disk partition.
Definition: disk.c:1682
signed int INT32
Definition: los_typedef.h:60
char CHAR
Definition: los_typedef.h:63
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
u32_t(* CmdCallBackFunc)(u32_t argc, const char **argv)
Definition: types_adapt.h:86
int VnodeDrop(void)
归还锁
Definition: vnode.c:292
int VnodeHold(void)
拿锁,封装互斥量
Definition: vnode.c:283
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
通过路径查询vnode节点
Definition: vnode.c:491