summaryrefslogtreecommitdiffstats
path: root/mtab.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-03-06 21:26:53 -0800
committerTavian Barnes <tavianator@tavianator.com>2019-03-06 21:28:48 -0800
commitd4a4ef26ef5245813ed74847147ce7f58c5a5232 (patch)
tree4458e5e04f07f41816aef62ad6dcf9d76cae561e /mtab.c
parentbae9b31ddfd377609b9de06937987d851d025e32 (diff)
downloadbfs-d4a4ef26ef5245813ed74847147ce7f58c5a5232.tar.xz
mtab: Fix implementation for all platforms
Diffstat (limited to 'mtab.c')
-rw-r--r--mtab.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/mtab.c b/mtab.c
index 0d5a153..0887f49 100644
--- a/mtab.c
+++ b/mtab.c
@@ -55,7 +55,7 @@ struct bfs_mtab {
/**
* Add an entry to the mount table.
*/
-static int bfs_mtab_push(struct bfs_mtab *mtab, dev_t dev, const char *type) {
+static int bfs_mtab_add(struct bfs_mtab *mtab, dev_t dev, const char *type) {
struct trie_leaf *leaf = trie_insert_mem(&mtab->types, &dev, sizeof(dev));
if (!leaf) {
return -1;
@@ -69,6 +69,7 @@ static int bfs_mtab_push(struct bfs_mtab *mtab, dev_t dev, const char *type) {
if (leaf->value) {
return 0;
} else {
+ trie_remove_mem(&mtab->types, leaf->key, leaf->length);
return -1;
}
}
@@ -98,7 +99,7 @@ struct bfs_mtab *parse_bfs_mtab() {
continue;
}
- if (bfs_mtab_push(mtab, sb.dev, mnt->mnt_type) != 0) {
+ if (bfs_mtab_add(mtab, sb.dev, mnt->mnt_type) != 0) {
goto fail_mtab;
}
}
@@ -125,13 +126,7 @@ fail:
if (!mtab) {
goto fail;
}
-
- mtab->size = 0;
- mtab->table = malloc(size*sizeof(*mtab->table));
- if (!mtab->table) {
- goto fail_mtab;
- }
- mtab->capacity = size;
+ trie_init(&mtab->types);
for (struct statfs *mnt = mntbuf; mnt < mntbuf + size; ++mnt) {
struct bfs_stat sb;
@@ -139,7 +134,7 @@ fail:
continue;
}
- if (bfs_mtab_push(mtab, sb.dev, mnt->f_fstypename) != 0) {
+ if (bfs_mtab_add(mtab, sb.dev, mnt->f_fstypename) != 0) {
goto fail_mtab;
}
}
@@ -162,9 +157,7 @@ fail:
if (!mtab) {
goto fail_file;
}
- mtab->table = NULL;
- mtab->size = 0;
- mtab->capacity = 0;
+ trie_init(&mtab->types);
struct mnttab mnt;
while (getmntent(file, &mnt) == 0) {
@@ -173,7 +166,7 @@ fail:
continue;
}
- if (bfs_mtab_push(mtab, sb.dev, mnt.mnt_fstype) != 0) {
+ if (bfs_mtab_add(mtab, sb.dev, mnt.mnt_fstype) != 0) {
goto fail_mtab;
}
}