aboutsummaryrefslogtreecommitdiff
path: root/df.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>1999-10-13 18:01:10 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>1999-10-13 18:01:10 +0000
commit40a1a9f2652bbc731f04bdd41e325b4a00c503c1 (patch)
tree685c18e7a6e52b315c9b8a142b8b21fc55e635fc /df.c
parentc488ae45854a2706fab2a7c5103fdb68ca6110bd (diff)
downloadbusybox-w32-40a1a9f2652bbc731f04bdd41e325b4a00c503c1.tar.gz
busybox-w32-40a1a9f2652bbc731f04bdd41e325b4a00c503c1.tar.bz2
busybox-w32-40a1a9f2652bbc731f04bdd41e325b4a00c503c1.zip
More stuff
git-svn-id: svn://busybox.net/trunk/busybox@21 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'df.c')
-rw-r--r--df.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/df.c b/df.c
index 8cc93814b..a777d70f4 100644
--- a/df.c
+++ b/df.c
@@ -43,6 +43,50 @@ df(char* device, const char * mountPoint)
43 return 0; 43 return 0;
44} 44}
45 45
46/*
47 * Given a block device, find the mount table entry if that block device
48 * is mounted.
49 *
50 * Given any other file (or directory), find the mount table entry for its
51 * filesystem.
52 */
53extern struct mntent *
54findMountPoint(const char* name, const char* table)
55{
56 struct stat s;
57 dev_t mountDevice;
58 FILE * mountTable;
59 struct mntent * mountEntry;
60
61 if ( stat(name, &s) != 0 )
62 return 0;
63
64 if ( (s.st_mode & S_IFMT) == S_IFBLK )
65 mountDevice = s.st_rdev;
66 else
67 mountDevice = s.st_dev;
68
69
70 if ( (mountTable = setmntent(table, "r")) == 0 )
71 return 0;
72
73 while ( (mountEntry = getmntent(mountTable)) != 0 ) {
74 if ( strcmp(name, mountEntry->mnt_dir) == 0
75 || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
76 break;
77 if ( stat(mountEntry->mnt_fsname, &s) == 0
78 && s.st_rdev == mountDevice ) /* Match the device. */
79 break;
80 if ( stat(mountEntry->mnt_dir, &s) == 0
81 && s.st_dev == mountDevice ) /* Match the directory's mount point. */
82 break;
83 }
84 endmntent(mountTable);
85 return mountEntry;
86}
87
88
89
46extern int 90extern int
47df_main(int argc, char * * argv) 91df_main(int argc, char * * argv)
48{ 92{
@@ -90,47 +134,3 @@ df_main(int argc, char * * argv)
90 134
91 135
92 136
93
94/*
95 * Given a block device, find the mount table entry if that block device
96 * is mounted.
97 *
98 * Given any other file (or directory), find the mount table entry for its
99 * filesystem.
100 */
101extern struct mntent *
102findMountPoint(const char* name, const char* table)
103{
104 struct stat s;
105 dev_t mountDevice;
106 FILE * mountTable;
107 struct mntent * mountEntry;
108
109 if ( stat(name, &s) != 0 )
110 return 0;
111
112 if ( (s.st_mode & S_IFMT) == S_IFBLK )
113 mountDevice = s.st_rdev;
114 else
115 mountDevice = s.st_dev;
116
117
118 if ( (mountTable = setmntent(table, "r")) == 0 )
119 return 0;
120
121 while ( (mountEntry = getmntent(mountTable)) != 0 ) {
122 if ( strcmp(name, mountEntry->mnt_dir) == 0
123 || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
124 break;
125 if ( stat(mountEntry->mnt_fsname, &s) == 0
126 && s.st_rdev == mountDevice ) /* Match the device. */
127 break;
128 if ( stat(mountEntry->mnt_dir, &s) == 0
129 && s.st_dev == mountDevice ) /* Match the directory's mount point. */
130 break;
131 }
132 endmntent(mountTable);
133 return mountEntry;
134}
135
136