7 const char df_usage[] = "df [filesystem ...]\n"
9 "\tPrint the filesystem space used and space available.\n";
13 df(const char * device, const char * mountPoint)
17 long blocks_percent_used;
19 if ( statfs(mountPoint, &s) != 0 ) {
20 name_and_error(mountPoint);
24 if ( s.f_blocks > 0 ) {
25 blocks_used = s.f_blocks - s.f_bfree;
26 blocks_percent_used = (long)
27 (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
31 "%-20s %7ld %7ld %7ld %5ld%% %s\n"
34 ,s.f_blocks - s.f_bfree
41 "%-20s %7.0f %7.0f %7.0f %5ld%% %s\n"
43 ,s.f_blocks * (s.f_bsize / 1024.0)
44 ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
45 ,s.f_bavail * (s.f_bsize / 1024.0)
55 df_main(struct FileInfo * i, int argc, char * * argv)
57 static const char header[] =
58 "Filesystem 1024-blocks Used Available Capacity Mounted on\n";
62 struct mntent * mountEntry;
66 if ( (mountEntry = findMountPoint(argv[1], "/etc/mtab")) == 0
67 && (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
69 fprintf(stderr, "%s: can't find mount point.\n"
73 status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
83 struct mntent * mountEntry;
85 if ( (mountTable = setmntent("/etc/mtab", "r")) == 0
86 && (mountTable = setmntent("/proc/mounts", "r")) == 0
88 name_and_error("/etc/mtab");
92 while ( (mountEntry = getmntent(mountTable)) != 0 ) {
94 mountEntry->mnt_fsname
95 ,mountEntry->mnt_dir);
99 endmntent(mountTable);