diff options
| author | Eric Andersen <andersen@codepoet.org> | 1999-10-06 20:25:32 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 1999-10-06 20:25:32 +0000 |
| commit | 17d49efd8ce6507152d78a70574193bb1b313af6 (patch) | |
| tree | 64e24302dc2575867d8a78897500e5a5b2a48398 /coreutils | |
| parent | 9d3aba7b37b275350a9fe0887871da9ba73dcbd7 (diff) | |
| download | busybox-w32-17d49efd8ce6507152d78a70574193bb1b313af6.tar.gz busybox-w32-17d49efd8ce6507152d78a70574193bb1b313af6.tar.bz2 busybox-w32-17d49efd8ce6507152d78a70574193bb1b313af6.zip | |
More stuff.
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/df.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index a0692afc5..bbda69456 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
| @@ -17,7 +17,7 @@ df(const char * device, const char * mountPoint) | |||
| 17 | long blocks_percent_used; | 17 | long blocks_percent_used; |
| 18 | 18 | ||
| 19 | if ( statfs(mountPoint, &s) != 0 ) { | 19 | if ( statfs(mountPoint, &s) != 0 ) { |
| 20 | name_and_error(mountPoint); | 20 | perror(mountPoint); |
| 21 | return 1; | 21 | return 1; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| @@ -52,7 +52,7 @@ df(const char * device, const char * mountPoint) | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | extern int | 54 | extern int |
| 55 | df_main(struct FileInfo * i, int argc, char * * argv) | 55 | df_main(int argc, char * * argv) |
| 56 | { | 56 | { |
| 57 | static const char header[] = | 57 | static const char header[] = |
| 58 | "Filesystem 1024-blocks Used Available Capacity Mounted on\n"; | 58 | "Filesystem 1024-blocks Used Available Capacity Mounted on\n"; |
| @@ -63,11 +63,9 @@ df_main(struct FileInfo * i, int argc, char * * argv) | |||
| 63 | int status; | 63 | int status; |
| 64 | 64 | ||
| 65 | while ( argc > 1 ) { | 65 | while ( argc > 1 ) { |
| 66 | if ( (mountEntry = findMountPoint(argv[1], "/etc/mtab")) == 0 | 66 | if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 ) |
| 67 | && (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 ) | ||
| 68 | { | 67 | { |
| 69 | fprintf(stderr, "%s: can't find mount point.\n" | 68 | fprintf(stderr, "%s: can't find mount point.\n" ,argv[1]); |
| 70 | ,argv[1]); | ||
| 71 | return 1; | 69 | return 1; |
| 72 | } | 70 | } |
| 73 | status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir); | 71 | status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir); |
| @@ -82,10 +80,8 @@ df_main(struct FileInfo * i, int argc, char * * argv) | |||
| 82 | FILE * mountTable; | 80 | FILE * mountTable; |
| 83 | struct mntent * mountEntry; | 81 | struct mntent * mountEntry; |
| 84 | 82 | ||
| 85 | if ( (mountTable = setmntent("/etc/mtab", "r")) == 0 | 83 | if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) { |
| 86 | && (mountTable = setmntent("/proc/mounts", "r")) == 0 | 84 | perror("/proc/mounts"); |
| 87 | ) { | ||
| 88 | name_and_error("/etc/mtab"); | ||
| 89 | return 1; | 85 | return 1; |
| 90 | } | 86 | } |
| 91 | 87 | ||
| @@ -101,3 +97,48 @@ df_main(struct FileInfo * i, int argc, char * * argv) | |||
| 101 | 97 | ||
| 102 | return 0; | 98 | return 0; |
| 103 | } | 99 | } |
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | |||
| 104 | /* | ||
| 105 | * Given a block device, find the mount table entry if that block device | ||
| 106 | * is mounted. | ||
| 107 | * | ||
| 108 | * Given any other file (or directory), find the mount table entry for its | ||
| 109 | * filesystem. | ||
| 110 | */ | ||
| 111 | extern struct mntent * | ||
| 112 | findMountPoint(const char * name, const char * table) | ||
| 113 | { | ||
| 114 | struct stat s; | ||
| 115 | dev_t mountDevice; | ||
| 116 | FILE * mountTable; | ||
| 117 | struct mntent * mountEntry; | ||
| 118 | |||
| 119 | if ( stat(name, &s) != 0 ) | ||
| 120 | return 0; | ||
| 121 | |||
| 122 | if ( (s.st_mode & S_IFMT) == S_IFBLK ) | ||
| 123 | mountDevice = s.st_rdev; | ||
| 124 | else | ||
| 125 | mountDevice = s.st_dev; | ||
| 126 | |||
| 127 | |||
| 128 | if ( (mountTable = setmntent(table, "r")) == 0 ) | ||
| 129 | return 0; | ||
| 130 | |||
| 131 | while ( (mountEntry = getmntent(mountTable)) != 0 ) { | ||
| 132 | if ( strcmp(name, mountEntry->mnt_dir) == 0 | ||
| 133 | || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */ | ||
| 134 | break; | ||
| 135 | if ( stat(mountEntry->mnt_fsname, &s) == 0 | ||
| 136 | && s.st_rdev == mountDevice ) /* Match the device. */ | ||
| 137 | break; | ||
| 138 | if ( stat(mountEntry->mnt_dir, &s) == 0 | ||
| 139 | && s.st_dev == mountDevice ) /* Match the directory's mount point. */ | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | endmntent(mountTable); | ||
| 143 | return mountEntry; | ||
| 144 | } | ||
