diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-27 17:29:09 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-27 17:29:09 +0000 |
| commit | cb1593bdcd9ab5d6ce565eec30eafb458738d378 (patch) | |
| tree | a50b391e7a9e4a001856aeb5b98bc1b52c8ef2b8 | |
| parent | 8aeacdeb7985d23b2d692fca7f2b77c16fa0a6ec (diff) | |
| download | busybox-w32-cb1593bdcd9ab5d6ce565eec30eafb458738d378.tar.gz busybox-w32-cb1593bdcd9ab5d6ce565eec30eafb458738d378.tar.bz2 busybox-w32-cb1593bdcd9ab5d6ce565eec30eafb458738d378.zip | |
erase_mtab: do not limit ourself to 40 mtab entries
git-svn-id: svn://busybox.net/trunk/busybox@16693 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | libbb/mtab.c | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/libbb/mtab.c b/libbb/mtab.c index cce1aac5c..18386efb5 100644 --- a/libbb/mtab.c +++ b/libbb/mtab.c | |||
| @@ -7,53 +7,42 @@ | |||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <unistd.h> | ||
| 12 | #include <errno.h> | ||
| 13 | #include <string.h> | ||
| 14 | #include <stdio.h> | ||
| 15 | #include <mntent.h> | 10 | #include <mntent.h> |
| 16 | #include "libbb.h" | 11 | #include "libbb.h" |
| 17 | 12 | ||
| 18 | #define MTAB_MAX_ENTRIES 40 | 13 | #if ENABLE_FEATURE_MTAB_SUPPORT |
| 19 | |||
| 20 | #ifdef CONFIG_FEATURE_MTAB_SUPPORT | ||
| 21 | void erase_mtab(const char *name) | 14 | void erase_mtab(const char *name) |
| 22 | { | 15 | { |
| 23 | struct mntent entries[MTAB_MAX_ENTRIES]; | 16 | struct mntent *entries = NULL; |
| 24 | int count = 0; | 17 | int i, count = 0; |
| 25 | FILE *mountTable = setmntent(bb_path_mtab_file, "r"); | 18 | FILE *mountTable; |
| 26 | struct mntent *m; | 19 | struct mntent *m; |
| 27 | 20 | ||
| 28 | /* Check if reading the mtab file failed */ | 21 | mountTable = setmntent(bb_path_mtab_file, "r"); |
| 29 | if (mountTable == 0 | 22 | /* Bummer. Fall back on trying the /proc filesystem */ |
| 30 | /* Bummer. fall back on trying the /proc filesystem */ | 23 | if (!mountTable) mountTable = setmntent("/proc/mounts", "r"); |
| 31 | && (mountTable = setmntent("/proc/mounts", "r")) == 0) { | 24 | if (!mountTable) { |
| 32 | bb_perror_msg(bb_path_mtab_file); | 25 | bb_perror_msg(bb_path_mtab_file); |
| 33 | return; | 26 | return; |
| 34 | } | 27 | } |
| 35 | 28 | ||
| 36 | while (((m = getmntent(mountTable)) != 0) && (count < MTAB_MAX_ENTRIES)) | 29 | while ((m = getmntent(mountTable)) != 0) { |
| 37 | { | 30 | i = count++; |
| 38 | entries[count].mnt_fsname = strdup(m->mnt_fsname); | 31 | entries = xrealloc(entries, count * sizeof(entries[0])); |
| 39 | entries[count].mnt_dir = strdup(m->mnt_dir); | 32 | entries[i].mnt_fsname = xstrdup(m->mnt_fsname); |
| 40 | entries[count].mnt_type = strdup(m->mnt_type); | 33 | entries[i].mnt_dir = xstrdup(m->mnt_dir); |
| 41 | entries[count].mnt_opts = strdup(m->mnt_opts); | 34 | entries[i].mnt_type = xstrdup(m->mnt_type); |
| 42 | entries[count].mnt_freq = m->mnt_freq; | 35 | entries[i].mnt_opts = xstrdup(m->mnt_opts); |
| 43 | entries[count].mnt_passno = m->mnt_passno; | 36 | entries[i].mnt_freq = m->mnt_freq; |
| 44 | count++; | 37 | entries[i].mnt_passno = m->mnt_passno; |
| 45 | } | 38 | } |
| 46 | endmntent(mountTable); | 39 | endmntent(mountTable); |
| 47 | if ((mountTable = setmntent(bb_path_mtab_file, "w"))) { | ||
| 48 | int i; | ||
| 49 | 40 | ||
| 41 | mountTable = setmntent(bb_path_mtab_file, "w"); | ||
| 42 | if (mountTable) { | ||
| 50 | for (i = 0; i < count; i++) { | 43 | for (i = 0; i < count; i++) { |
| 51 | int result = (strcmp(entries[i].mnt_fsname, name) == 0 | 44 | if (strcmp(entries[i].mnt_fsname, name) != 0 |
| 52 | || strcmp(entries[i].mnt_dir, name) == 0); | 45 | && strcmp(entries[i].mnt_dir, name) != 0) |
| 53 | |||
| 54 | if (result) | ||
| 55 | continue; | ||
| 56 | else | ||
| 57 | addmntent(mountTable, &entries[i]); | 46 | addmntent(mountTable, &entries[i]); |
| 58 | } | 47 | } |
| 59 | endmntent(mountTable); | 48 | endmntent(mountTable); |
