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

47
df.c
View File

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