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 tarball for details.
13 #if ENABLE_FEATURE_MTAB_SUPPORT
14 void FAST_FUNC erase_mtab(const char *name)
16 struct mntent *entries;
21 mountTable = setmntent(bb_path_mtab_file, "r");
22 /* Bummer. Fall back on trying the /proc filesystem */
23 if (!mountTable) mountTable = setmntent("/proc/mounts", "r");
25 bb_perror_msg(bb_path_mtab_file);
31 while ((m = getmntent(mountTable)) != 0) {
32 entries = xrealloc_vector(entries, 3, count);
33 entries[count].mnt_fsname = xstrdup(m->mnt_fsname);
34 entries[count].mnt_dir = xstrdup(m->mnt_dir);
35 entries[count].mnt_type = xstrdup(m->mnt_type);
36 entries[count].mnt_opts = xstrdup(m->mnt_opts);
37 entries[count].mnt_freq = m->mnt_freq;
38 entries[count].mnt_passno = m->mnt_passno;
41 endmntent(mountTable);
43 //TODO: make update atomic
44 mountTable = setmntent(bb_path_mtab_file, "w");
46 for (i = 0; i < count; i++) {
47 if (strcmp(entries[i].mnt_fsname, name) != 0
48 && strcmp(entries[i].mnt_dir, name) != 0)
49 addmntent(mountTable, &entries[i]);
51 endmntent(mountTable);
52 } else if (errno != EROFS)
53 bb_perror_msg(bb_path_mtab_file);