diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-06 22:06:29 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-06 22:06:29 +0000 |
commit | 5c3199e0a519695c367b773e179b5458670f452b (patch) | |
tree | adb0850c32c732420d54b697c5bdb18cf3b4f5d0 | |
parent | 17d49efd8ce6507152d78a70574193bb1b313af6 (diff) | |
download | busybox-w32-5c3199e0a519695c367b773e179b5458670f452b.tar.gz busybox-w32-5c3199e0a519695c367b773e179b5458670f452b.tar.bz2 busybox-w32-5c3199e0a519695c367b773e179b5458670f452b.zip |
Made df work
-rw-r--r-- | coreutils/df.c | 49 | ||||
-rw-r--r-- | df.c | 49 |
2 files changed, 36 insertions, 62 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index bbda69456..354b2a7ca 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -26,25 +26,14 @@ df(const char * device, const char * mountPoint) | |||
26 | blocks_percent_used = (long) | 26 | blocks_percent_used = (long) |
27 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 27 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
28 | 28 | ||
29 | /* | ||
30 | printf( | ||
31 | "%-20s %7ld %7ld %7ld %5ld%% %s\n" | ||
32 | ,device | ||
33 | ,s.f_blocks | ||
34 | ,s.f_blocks - s.f_bfree | ||
35 | ,s.f_bavail | ||
36 | ,blocks_percent_used | ||
37 | ,mountPoint); | ||
38 | */ | ||
39 | |||
40 | printf( | 29 | printf( |
41 | "%-20s %7.0f %7.0f %7.0f %5ld%% %s\n" | 30 | "%-20s %9ld %9ld %9ld %3ld%% %s\n", |
42 | ,device | 31 | device, |
43 | ,s.f_blocks * (s.f_bsize / 1024.0) | 32 | (long)(s.f_blocks * (s.f_bsize / 1024.0)), |
44 | ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0) | 33 | (long)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)), |
45 | ,s.f_bavail * (s.f_bsize / 1024.0) | 34 | (long)(s.f_bavail * (s.f_bsize / 1024.0)), |
46 | ,blocks_percent_used | 35 | blocks_percent_used, |
47 | ,mountPoint); | 36 | mountPoint); |
48 | 37 | ||
49 | } | 38 | } |
50 | 39 | ||
@@ -54,13 +43,12 @@ df(const char * device, const char * mountPoint) | |||
54 | extern int | 43 | extern int |
55 | df_main(int argc, char * * argv) | 44 | df_main(int argc, char * * argv) |
56 | { | 45 | { |
57 | static const char header[] = | 46 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", |
58 | "Filesystem 1024-blocks Used Available Capacity Mounted on\n"; | 47 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); |
59 | printf(header); | ||
60 | 48 | ||
61 | if ( argc > 1 ) { | 49 | if ( argc > 1 ) { |
62 | struct mntent * mountEntry; | 50 | struct mntent* mountEntry; |
63 | int status; | 51 | int status; |
64 | 52 | ||
65 | while ( argc > 1 ) { | 53 | while ( argc > 1 ) { |
66 | if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 ) | 54 | if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 ) |
@@ -80,16 +68,15 @@ df_main(int argc, char * * argv) | |||
80 | FILE * mountTable; | 68 | FILE * mountTable; |
81 | struct mntent * mountEntry; | 69 | struct mntent * mountEntry; |
82 | 70 | ||
83 | if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) { | 71 | mountTable = setmntent("/proc/mounts", "r"); |
72 | if ( mountTable == 0) { | ||
84 | perror("/proc/mounts"); | 73 | perror("/proc/mounts"); |
85 | return 1; | 74 | exit( FALSE); |
86 | } | 75 | } |
87 | 76 | ||
88 | while ( (mountEntry = getmntent(mountTable)) != 0 ) { | 77 | while ( (mountEntry = getmntent (mountTable))) { |
89 | int status = df( | 78 | int status=df(mountEntry->mnt_fsname ,mountEntry->mnt_dir); |
90 | mountEntry->mnt_fsname | 79 | if (status) |
91 | ,mountEntry->mnt_dir); | ||
92 | if ( status != 0 ) | ||
93 | return status; | 80 | return status; |
94 | } | 81 | } |
95 | endmntent(mountTable); | 82 | endmntent(mountTable); |
@@ -109,7 +96,7 @@ df_main(int argc, char * * argv) | |||
109 | * filesystem. | 96 | * filesystem. |
110 | */ | 97 | */ |
111 | extern struct mntent * | 98 | extern struct mntent * |
112 | findMountPoint(const char * name, const char * table) | 99 | findMountPoint(const char* name, const char* table) |
113 | { | 100 | { |
114 | struct stat s; | 101 | struct stat s; |
115 | dev_t mountDevice; | 102 | dev_t mountDevice; |
@@ -26,25 +26,14 @@ df(const char * device, const char * mountPoint) | |||
26 | blocks_percent_used = (long) | 26 | blocks_percent_used = (long) |
27 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 27 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
28 | 28 | ||
29 | /* | ||
30 | printf( | ||
31 | "%-20s %7ld %7ld %7ld %5ld%% %s\n" | ||
32 | ,device | ||
33 | ,s.f_blocks | ||
34 | ,s.f_blocks - s.f_bfree | ||
35 | ,s.f_bavail | ||
36 | ,blocks_percent_used | ||
37 | ,mountPoint); | ||
38 | */ | ||
39 | |||
40 | printf( | 29 | printf( |
41 | "%-20s %7.0f %7.0f %7.0f %5ld%% %s\n" | 30 | "%-20s %9ld %9ld %9ld %3ld%% %s\n", |
42 | ,device | 31 | device, |
43 | ,s.f_blocks * (s.f_bsize / 1024.0) | 32 | (long)(s.f_blocks * (s.f_bsize / 1024.0)), |
44 | ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0) | 33 | (long)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)), |
45 | ,s.f_bavail * (s.f_bsize / 1024.0) | 34 | (long)(s.f_bavail * (s.f_bsize / 1024.0)), |
46 | ,blocks_percent_used | 35 | blocks_percent_used, |
47 | ,mountPoint); | 36 | mountPoint); |
48 | 37 | ||
49 | } | 38 | } |
50 | 39 | ||
@@ -54,13 +43,12 @@ df(const char * device, const char * mountPoint) | |||
54 | extern int | 43 | extern int |
55 | df_main(int argc, char * * argv) | 44 | df_main(int argc, char * * argv) |
56 | { | 45 | { |
57 | static const char header[] = | 46 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", |
58 | "Filesystem 1024-blocks Used Available Capacity Mounted on\n"; | 47 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); |
59 | printf(header); | ||
60 | 48 | ||
61 | if ( argc > 1 ) { | 49 | if ( argc > 1 ) { |
62 | struct mntent * mountEntry; | 50 | struct mntent* mountEntry; |
63 | int status; | 51 | int status; |
64 | 52 | ||
65 | while ( argc > 1 ) { | 53 | while ( argc > 1 ) { |
66 | if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 ) | 54 | if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 ) |
@@ -80,16 +68,15 @@ df_main(int argc, char * * argv) | |||
80 | FILE * mountTable; | 68 | FILE * mountTable; |
81 | struct mntent * mountEntry; | 69 | struct mntent * mountEntry; |
82 | 70 | ||
83 | if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) { | 71 | mountTable = setmntent("/proc/mounts", "r"); |
72 | if ( mountTable == 0) { | ||
84 | perror("/proc/mounts"); | 73 | perror("/proc/mounts"); |
85 | return 1; | 74 | exit( FALSE); |
86 | } | 75 | } |
87 | 76 | ||
88 | while ( (mountEntry = getmntent(mountTable)) != 0 ) { | 77 | while ( (mountEntry = getmntent (mountTable))) { |
89 | int status = df( | 78 | int status=df(mountEntry->mnt_fsname ,mountEntry->mnt_dir); |
90 | mountEntry->mnt_fsname | 79 | if (status) |
91 | ,mountEntry->mnt_dir); | ||
92 | if ( status != 0 ) | ||
93 | return status; | 80 | return status; |
94 | } | 81 | } |
95 | endmntent(mountTable); | 82 | endmntent(mountTable); |
@@ -109,7 +96,7 @@ df_main(int argc, char * * argv) | |||
109 | * filesystem. | 96 | * filesystem. |
110 | */ | 97 | */ |
111 | extern struct mntent * | 98 | extern struct mntent * |
112 | findMountPoint(const char * name, const char * table) | 99 | findMountPoint(const char* name, const char* table) |
113 | { | 100 | { |
114 | struct stat s; | 101 | struct stat s; |
115 | dev_t mountDevice; | 102 | dev_t mountDevice; |