summaryrefslogtreecommitdiffstats
path: root/mtab.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-09-09 12:01:23 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-09-09 12:01:23 -0400
commit55470cc8835ef774bf7defa9a4b319c8fa9d2f4b (patch)
treea13936a4daa18239da1bb661f39f66b5489324c0 /mtab.c
parent4f859751e3b0f16177c34263c2aebadbbe2e43d1 (diff)
downloadbfs-55470cc8835ef774bf7defa9a4b319c8fa9d2f4b.tar.xz
mtab: Add support for Solaris
Diffstat (limited to 'mtab.c')
-rw-r--r--mtab.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/mtab.c b/mtab.c
index a43e662..fb3f85b 100644
--- a/mtab.c
+++ b/mtab.c
@@ -30,14 +30,20 @@
# define BFS_MNTENT 1
#elif BSD
# define BFS_MNTINFO 1
+#elif __SVR4
+# define BFS_MNTTAB 1
#endif
#if BFS_MNTENT
# include <mntent.h>
# include <paths.h>
+# include <stdio.h>
#elif BFS_MNTINFO
# include <sys/mount.h>
# include <sys/ucred.h>
+#elif BFS_MNTTAB
+# include <stdio.h>
+# include <sys/mnttab.h>
#endif
/**
@@ -162,6 +168,43 @@ fail_mtab:
fail:
return NULL;
+#elif BFS_MNTTAB
+
+ FILE *file = fopen(MNTTAB, "r");
+ if (!file) {
+ goto fail;
+ }
+
+ struct bfs_mtab *mtab = malloc(sizeof(*mtab));
+ if (!mtab) {
+ goto fail_file;
+ }
+ mtab->table = NULL;
+ mtab->size = 0;
+ mtab->capacity = 0;
+
+ struct mnttab mnt;
+ while (getmntent(file, &mnt) == 0) {
+ struct stat sb;
+ if (stat(mnt.mnt_mountp, &sb) != 0) {
+ continue;
+ }
+
+ if (bfs_mtab_push(mtab, sb.st_dev, mnt.mnt_fstype) != 0) {
+ goto fail_mtab;
+ }
+ }
+
+ fclose(file);
+ return mtab;
+
+fail_mtab:
+ free_bfs_mtab(mtab);
+fail_file:
+ fclose(file);
+fail:
+ return NULL;
+
#else
errno = ENOTSUP;