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

re-write for #1138
This commit is contained in:
bernard 2017-12-31 10:46:24 +08:00
parent 90e8f95102
commit 872975b0ab
2 changed files with 37 additions and 2 deletions

View File

@ -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);

View File

@ -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)