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.
18 #define MTAB_MAX_ENTRIES 40
20 #ifdef CONFIG_FEATURE_MTAB_SUPPORT
21 void erase_mtab(const char *name)
23 struct mntent entries[MTAB_MAX_ENTRIES];
25 FILE *mountTable = setmntent(bb_path_mtab_file, "r");
28 /* Check if reading the mtab file failed */
30 /* Bummer. fall back on trying the /proc filesystem */
31 && (mountTable = setmntent("/proc/mounts", "r")) == 0) {
32 bb_perror_msg(bb_path_mtab_file);
36 while (((m = getmntent(mountTable)) != 0) && (count < MTAB_MAX_ENTRIES))
38 entries[count].mnt_fsname = strdup(m->mnt_fsname);
39 entries[count].mnt_dir = strdup(m->mnt_dir);
40 entries[count].mnt_type = strdup(m->mnt_type);
41 entries[count].mnt_opts = strdup(m->mnt_opts);
42 entries[count].mnt_freq = m->mnt_freq;
43 entries[count].mnt_passno = m->mnt_passno;
46 endmntent(mountTable);
47 if ((mountTable = setmntent(bb_path_mtab_file, "w"))) {
50 for (i = 0; i < count; i++) {
51 int result = (strcmp(entries[i].mnt_fsname, name) == 0
52 || strcmp(entries[i].mnt_dir, name) == 0);
57 addmntent(mountTable, &entries[i]);
59 endmntent(mountTable);
60 } else if (errno != EROFS)
61 bb_perror_msg(bb_path_mtab_file);