1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 #if ENABLE_FEATURE_MTAB_SUPPORT
13 void FAST_FUNC erase_mtab(const char *name)
15 struct mntent *entries;
20 mountTable = setmntent(bb_path_mtab_file, "r");
21 /* Bummer. Fall back on trying the /proc filesystem */
22 if (!mountTable) mountTable = setmntent("/proc/mounts", "r");
24 bb_perror_msg(bb_path_mtab_file);
30 while ((m = getmntent(mountTable)) != 0) {
31 entries = xrealloc_vector(entries, 3, count);
32 entries[count].mnt_fsname = xstrdup(m->mnt_fsname);
33 entries[count].mnt_dir = xstrdup(m->mnt_dir);
34 entries[count].mnt_type = xstrdup(m->mnt_type);
35 entries[count].mnt_opts = xstrdup(m->mnt_opts);
36 entries[count].mnt_freq = m->mnt_freq;
37 entries[count].mnt_passno = m->mnt_passno;
40 endmntent(mountTable);
42 //TODO: make update atomic
43 mountTable = setmntent(bb_path_mtab_file, "w");
45 for (i = 0; i < count; i++) {
46 if (strcmp(entries[i].mnt_fsname, name) != 0
47 && strcmp(entries[i].mnt_dir, name) != 0)
48 addmntent(mountTable, &entries[i]);
50 endmntent(mountTable);
51 } else if (errno != EROFS)
52 bb_perror_msg(bb_path_mtab_file);