diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index f6c210ddb..c1f31a2f8 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -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); diff --git a/components/finsh/msh_cmd.c b/components/finsh/msh_cmd.c index b5881d897..f184f1f33 100644 --- a/components/finsh/msh_cmd.c +++ b/components/finsh/msh_cmd.c @@ -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)