提交 872975b0 编写于 作者: B bernard

[DFS] add df cmd in msh and provide better display.

re-write for #1138
上级 90e8f951
......@@ -540,9 +540,13 @@ FINSH_FUNCTION_EXPORT(mkfs, make a file system);
int df(const char *path)
{
int result;
int minor = 0;
long long cap;
struct statfs buffer;
int unit_index = 0;
char *unit_str[] = {"KB", "MB", "GB"};
result = dfs_statfs(path ? path : NULL, &buffer);
if (result != 0)
{
......@@ -551,8 +555,16 @@ int df(const char *path)
}
cap = buffer.f_bsize * buffer.f_bfree / 1024;
rt_kprintf("disk free: %d KB [ %d block, %d bytes per block ]\n",
(unsigned long)cap, buffer.f_bfree, buffer.f_bsize);
for (unit_index = 0; unit_index < 3; unit_index ++)
{
if (cap < 1024) break;
minor = (cap % 1024) * 10 / 1024; /* only one decimal point */
cap = cap / 1024;
}
rt_kprintf("disk free: %d.%d %s [ %d block, %d bytes per block ]\n",
(unsigned long)cap, minor, unit_str[unit_index], buffer.f_bfree, buffer.f_bsize);
return 0;
}
FINSH_FUNCTION_EXPORT(df, get disk free);
......
......@@ -255,6 +255,29 @@ int cmd_mkfs(int argc, char **argv)
}
FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkfs, __cmd_mkfs, format disk with file system);
extern int df(const char *path);
int cmd_df(int argc, char** argv)
{
if (argc != 2)
{
df("/");
}
else
{
if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0))
{
rt_kprintf("df [path]\n");
}
else
{
df(argv[1]);
}
}
return 0;
}
FINSH_FUNCTION_EXPORT_ALIAS(cmd_df, __cmd_df, disk free);
int cmd_echo(int argc, char** argv)
{
if (argc == 2)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册