Made df work

This commit is contained in:
Eric Andersen 1999-10-06 22:06:29 +00:00
parent 17d49efd8c
commit 5c3199e0a5
2 changed files with 36 additions and 62 deletions

View File

@ -26,25 +26,14 @@ df(const char * device, const char * mountPoint)
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/*
printf(
"%-20s %7ld %7ld %7ld %5ld%% %s\n"
,device
,s.f_blocks
,s.f_blocks - s.f_bfree
,s.f_bavail
,blocks_percent_used
,mountPoint);
*/
printf(
"%-20s %7.0f %7.0f %7.0f %5ld%% %s\n"
,device
,s.f_blocks * (s.f_bsize / 1024.0)
,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
,s.f_bavail * (s.f_bsize / 1024.0)
,blocks_percent_used
,mountPoint);
"%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long)(s.f_blocks * (s.f_bsize / 1024.0)),
(long)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
(long)(s.f_bavail * (s.f_bsize / 1024.0)),
blocks_percent_used,
mountPoint);
}
@ -54,9 +43,8 @@ df(const char * device, const char * mountPoint)
extern int
df_main(int argc, char * * argv)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
printf(header);
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
if ( argc > 1 ) {
struct mntent* mountEntry;
@ -80,16 +68,15 @@ df_main(int argc, char * * argv)
FILE * mountTable;
struct mntent * mountEntry;
if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) {
mountTable = setmntent("/proc/mounts", "r");
if ( mountTable == 0) {
perror("/proc/mounts");
return 1;
exit( FALSE);
}
while ( (mountEntry = getmntent(mountTable)) != 0 ) {
int status = df(
mountEntry->mnt_fsname
,mountEntry->mnt_dir);
if ( status != 0 )
while ( (mountEntry = getmntent (mountTable))) {
int status=df(mountEntry->mnt_fsname ,mountEntry->mnt_dir);
if (status)
return status;
}
endmntent(mountTable);

43
df.c
View File

@ -26,25 +26,14 @@ df(const char * device, const char * mountPoint)
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/*
printf(
"%-20s %7ld %7ld %7ld %5ld%% %s\n"
,device
,s.f_blocks
,s.f_blocks - s.f_bfree
,s.f_bavail
,blocks_percent_used
,mountPoint);
*/
printf(
"%-20s %7.0f %7.0f %7.0f %5ld%% %s\n"
,device
,s.f_blocks * (s.f_bsize / 1024.0)
,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
,s.f_bavail * (s.f_bsize / 1024.0)
,blocks_percent_used
,mountPoint);
"%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long)(s.f_blocks * (s.f_bsize / 1024.0)),
(long)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
(long)(s.f_bavail * (s.f_bsize / 1024.0)),
blocks_percent_used,
mountPoint);
}
@ -54,9 +43,8 @@ df(const char * device, const char * mountPoint)
extern int
df_main(int argc, char * * argv)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
printf(header);
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
if ( argc > 1 ) {
struct mntent* mountEntry;
@ -80,16 +68,15 @@ df_main(int argc, char * * argv)
FILE * mountTable;
struct mntent * mountEntry;
if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) {
mountTable = setmntent("/proc/mounts", "r");
if ( mountTable == 0) {
perror("/proc/mounts");
return 1;
exit( FALSE);
}
while ( (mountEntry = getmntent(mountTable)) != 0 ) {
int status = df(
mountEntry->mnt_fsname
,mountEntry->mnt_dir);
if ( status != 0 )
while ( (mountEntry = getmntent (mountTable))) {
int status=df(mountEntry->mnt_fsname ,mountEntry->mnt_dir);
if (status)
return status;
}
endmntent(mountTable);