aboutsummaryrefslogtreecommitdiff
path: root/umount.c
diff options
context:
space:
mode:
Diffstat (limited to 'umount.c')
-rw-r--r--umount.c192
1 files changed, 97 insertions, 95 deletions
diff --git a/umount.c b/umount.c
index a2ca8c74a..b58b1a08c 100644
--- a/umount.c
+++ b/umount.c
@@ -29,6 +29,7 @@
29#include <fstab.h> 29#include <fstab.h>
30#include <errno.h> 30#include <errno.h>
31 31
32
32static const char umount_usage[] = 33static const char umount_usage[] =
33 "umount [flags] filesystem|directory\n\n" 34 "umount [flags] filesystem|directory\n\n"
34 "Flags:\n" "\t-a:\tUnmount all file systems" 35 "Flags:\n" "\t-a:\tUnmount all file systems"
@@ -57,7 +58,99 @@ static int umountAll = FALSE;
57static int doRemount = FALSE; 58static int doRemount = FALSE;
58extern const char mtab_file[]; /* Defined in utility.c */ 59extern const char mtab_file[]; /* Defined in utility.c */
59 60
60#define MIN(x,y) (x > y ? x : y) 61
62/* These functions are here because the getmntent functions do not appear
63 * to be re-entrant, which leads to all sorts of problems when we try to
64 * use them recursively - randolph
65 */
66void mtab_read(void)
67{
68 struct _mtab_entry_t *entry = NULL;
69 struct mntent *e;
70 FILE *fp;
71
72 if (mtab_cache != NULL)
73 return;
74
75 if ((fp = setmntent(mtab_file, "r")) == NULL) {
76 fprintf(stderr, "Cannot open %s\n", mtab_file);
77 return;
78 }
79 while ((e = getmntent(fp))) {
80 entry = malloc(sizeof(struct _mtab_entry_t));
81
82 entry->device = strdup(e->mnt_fsname);
83 entry->mountpt = strdup(e->mnt_dir);
84 entry->next = mtab_cache;
85 mtab_cache = entry;
86 }
87 endmntent(fp);
88}
89
90char *mtab_getinfo(const char *match, const char which)
91{
92 struct _mtab_entry_t *cur = mtab_cache;
93
94 while (cur) {
95 if (strcmp(cur->mountpt, match) == 0 ||
96 strcmp(cur->device, match) == 0) {
97 if (which == MTAB_GETMOUNTPT) {
98 return cur->mountpt;
99 } else {
100#if !defined BB_MTAB
101 if (strcmp(cur->device, "/dev/root") == 0) {
102 struct fstab *fstabItem;
103
104 fstabItem = getfsfile("/");
105 if (fstabItem != NULL)
106 return fstabItem->fs_spec;
107 }
108#endif
109 return cur->device;
110 }
111 }
112 cur = cur->next;
113 }
114 return NULL;
115}
116
117char *mtab_first(void **iter)
118{
119 struct _mtab_entry_t *mtab_iter;
120
121 if (!iter)
122 return NULL;
123 mtab_iter = mtab_cache;
124 *iter = (void *) mtab_iter;
125 return mtab_next(iter);
126}
127
128char *mtab_next(void **iter)
129{
130 char *mp;
131
132 if (iter == NULL || *iter == NULL)
133 return NULL;
134 mp = ((struct _mtab_entry_t *) (*iter))->mountpt;
135 *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next;
136 return mp;
137}
138
139void mtab_free(void)
140{
141 struct _mtab_entry_t *this, *next;
142
143 this = mtab_cache;
144 while (this) {
145 next = this->next;
146 if (this->device)
147 free(this->device);
148 if (this->mountpt)
149 free(this->mountpt);
150 free(this);
151 this = next;
152 }
153}
61 154
62static int do_umount(const char *name, int useMtab) 155static int do_umount(const char *name, int useMtab)
63{ 156{
@@ -105,6 +198,9 @@ static int umount_all(int useMtab)
105 void *iter; 198 void *iter;
106 199
107 for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) { 200 for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) {
201 /* Never umount /proc on a umount -a */
202 if (strstr(mountpt, "proc")!= NULL)
203 continue;
108 status = do_umount(mountpt, useMtab); 204 status = do_umount(mountpt, useMtab);
109 if (status != 0) { 205 if (status != 0) {
110 /* Don't bother retrying the umount on busy devices */ 206 /* Don't bother retrying the umount on busy devices */
@@ -163,97 +259,3 @@ extern int umount_main(int argc, char **argv)
163 } 259 }
164} 260}
165 261
166
167
168/* These functions are here because the getmntent functions do not appear
169 * to be re-entrant, which leads to all sorts of problems when we try to
170 * use them recursively - randolph
171 */
172void mtab_read(void)
173{
174 struct _mtab_entry_t *entry = NULL;
175 struct mntent *e;
176 FILE *fp;
177
178 if (mtab_cache != NULL)
179 return;
180
181 if ((fp = setmntent(mtab_file, "r")) == NULL) {
182 fprintf(stderr, "Cannot open %s\n", mtab_file);
183 return;
184 }
185 while ((e = getmntent(fp))) {
186 entry = malloc(sizeof(struct _mtab_entry_t));
187
188 entry->device = strdup(e->mnt_fsname);
189 entry->mountpt = strdup(e->mnt_dir);
190 entry->next = mtab_cache;
191 mtab_cache = entry;
192 }
193 endmntent(fp);
194}
195
196char *mtab_getinfo(const char *match, const char which)
197{
198 struct _mtab_entry_t *cur = mtab_cache;
199
200 while (cur) {
201 if (strcmp(cur->mountpt, match) == 0 ||
202 strcmp(cur->device, match) == 0) {
203 if (which == MTAB_GETMOUNTPT) {
204 return cur->mountpt;
205 } else {
206#if !defined BB_MTAB
207 if (strcmp(cur->device, "/dev/root") == 0) {
208 struct fstab *fstabItem;
209
210 fstabItem = getfsfile("/");
211 if (fstabItem != NULL)
212 return fstabItem->fs_spec;
213 }
214#endif
215 return cur->device;
216 }
217 }
218 cur = cur->next;
219 }
220 return NULL;
221}
222
223char *mtab_first(void **iter)
224{
225 struct _mtab_entry_t *mtab_iter;
226
227 if (!iter)
228 return NULL;
229 mtab_iter = mtab_cache;
230 *iter = (void *) mtab_iter;
231 return mtab_next(iter);
232}
233
234char *mtab_next(void **iter)
235{
236 char *mp;
237
238 if (iter == NULL || *iter == NULL)
239 return NULL;
240 mp = ((struct _mtab_entry_t *) (*iter))->mountpt;
241 *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next;
242 return mp;
243}
244
245void mtab_free(void)
246{
247 struct _mtab_entry_t *this, *next;
248
249 this = mtab_cache;
250 while (this) {
251 next = this->next;
252 if (this->device)
253 free(this->device);
254 if (this->mountpt)
255 free(this->mountpt);
256 free(this);
257 this = next;
258 }
259}