MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / df

Function df

components/dfs/dfs_v1/src/dfs_fs.c:623–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621FINSH_FUNCTION_EXPORT(mkfs, make a file system);
622
623int df(const char *path)
624{
625 int result;
626 int minor = 0;
627 long long cap;
628 struct statfs buffer;
629
630 int unit_index = 0;
631 char *unit_str[] = {"KB", "MB", "GB"};
632
633 result = dfs_statfs(path ? path : NULL, &buffer);
634 if (result != 0)
635 {
636 if (rt_get_errno() == -ENOSYS)
637 rt_kprintf("The function is not implemented.\n");
638 else
639 rt_kprintf("statfs failed: errno=%d.\n", rt_get_errno());
640 return -1;
641 }
642
643 cap = ((long long)buffer.f_bsize) * ((long long)buffer.f_bfree) / 1024LL;
644 for (unit_index = 0; unit_index < 2; unit_index ++)
645 {
646 if (cap < 1024) break;
647
648 minor = (cap % 1024) * 10 / 1024; /* only one decimal point */
649 cap = cap / 1024;
650 }
651
652 rt_kprintf("disk free: %d.%d %s [ %d block, %d bytes per block ]\n",
653 (unsigned long)cap, minor, unit_str[unit_index], buffer.f_bfree, buffer.f_bsize);
654 return 0;
655}
656FINSH_FUNCTION_EXPORT(df, get disk free);
657#endif
658

Callers 1

cmd_dfFunction · 0.85

Calls 3

rt_get_errnoFunction · 0.85
rt_kprintfFunction · 0.85
dfs_statfsFunction · 0.70

Tested by

no test coverage detected