aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-03-07 20:56:56 +0100
committerDuncaen <mail@duncano.de>2017-03-07 21:01:11 +0100
commite911399a7dba86e47e653f00d42359c8039c4c93 (patch)
tree29076cf4f634f0bedf9f4e547d2b1dec8be41b1f
parent1b8815c48e703ed91d754f77170d7cacd777bd5b (diff)
downloadlobase-e911399a7dba86e47e653f00d42359c8039c4c93.tar.gz
lib/libopenbsd: add poor mans statfs and getfsstat compatibility
-rw-r--r--include/sys/mount.h40
-rw-r--r--lib/libopenbsd/Makefile5
-rw-r--r--lib/libopenbsd/statfs.c7
-rw-r--r--lib/libopenbsd/sys/getfsstat.c41
-rw-r--r--lib/libopenbsd/sys/statfs.c12
5 files changed, 98 insertions, 7 deletions
diff --git a/include/sys/mount.h b/include/sys/mount.h
index 09a2eda..c333b7b 100644
--- a/include/sys/mount.h
+++ b/include/sys/mount.h
@@ -1,2 +1,42 @@
#include <sys/vfs.h>
#include_next <sys/mount.h>
+
+#ifndef _COMPAT_SYS_MOUNT_H_
+#define _COMPAT_SYS_MOUNT_H_
+
+#include <stdlib.h>
+
+#define MNT_NOWAIT 0x01
+#define MNT_WAIT 0x02
+#define MNT_LOCAL 0x10
+#define MFSNAMELEN 128
+#define MNAMELEN 128
+
+union mount_info {
+
+};
+
+struct openbsd_statfs {
+ struct statfs buf;
+ char f_fstypename[MFSNAMELEN]; /* fs type name */
+ char f_mntonname[MNAMELEN]; /* directory on which mounted */
+ char f_mntfromname[MNAMELEN]; /* mounted file system */
+ char f_mntfromspec[MNAMELEN]; /* special for mount request */
+ union mount_info mount_info; /* per-filesystem mount options */
+};
+
+#define statfs openbsd_statfs
+
+#define f_blocks buf.f_blocks
+#define f_bsize buf.f_bsize
+#define f_bfree buf.f_bfree
+#define f_bavail buf.f_bavail
+
+#define f_files buf.f_files
+#define f_ffree buf.f_ffree
+#define f_flags buf.f_flags
+
+int getfsstat(struct statfs *, size_t, int);
+int openbsd_statfs(const char *, struct statfs *);
+
+#endif /* _COMPAT_SYS_MOUNT_H_ */
diff --git a/lib/libopenbsd/Makefile b/lib/libopenbsd/Makefile
index ec8329a..77af8e6 100644
--- a/lib/libopenbsd/Makefile
+++ b/lib/libopenbsd/Makefile
@@ -55,6 +55,11 @@ ifneq ($(HAVE_GETDTABLECOUNT),1)
SRCS += sys/getdtablecount.c
endif
+ifneq ($(HAVE_GETFSSTAT),1)
+ SRCS += sys/getfsstat.c
+ SRCS += sys/statfs.c
+endif
+
$(GEN_SRCS) : % : hash/helper.c
hash/sha1hl.c:
diff --git a/lib/libopenbsd/statfs.c b/lib/libopenbsd/statfs.c
deleted file mode 100644
index 6f5ae38..0000000
--- a/lib/libopenbsd/statfs.c
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-int
-statfs(const char *path, struct statfs *buf)
-{
-
-}
diff --git a/lib/libopenbsd/sys/getfsstat.c b/lib/libopenbsd/sys/getfsstat.c
new file mode 100644
index 0000000..2013139
--- /dev/null
+++ b/lib/libopenbsd/sys/getfsstat.c
@@ -0,0 +1,41 @@
+#include <sys/mount.h>
+
+#include <stdio.h>
+#include <paths.h>
+#include <stdlib.h>
+#include <mntent.h>
+#include <string.h>
+
+/* sys/mount.h defines statfs as openbsd_statfs, here i need the original one */
+#undef statfs
+
+int
+getfsstat(struct openbsd_statfs *buf, size_t bufsize, int flags)
+{
+ struct openbsd_statfs *cur;
+ struct mntent *m;
+ FILE *fp;
+ int n, max;
+
+ if (!(fp = setmntent(_PATH_MOUNTED, "r")))
+ return -1;
+
+ n = 0;
+ max = (bufsize / sizeof (struct openbsd_statfs));
+ while ((m = getmntent(fp))) {
+ if (!buf) {
+ n++;
+ continue;
+ }
+ if (n+1 >= max)
+ break;
+ cur = &buf[n++];
+ statfs(m->mnt_dir, &cur->buf);
+ strlcpy(cur->f_fstypename, m->mnt_type, sizeof (cur->f_fstypename));
+ strlcpy(cur->f_mntfromname, m->mnt_fsname, sizeof (cur->f_mntfromname));
+ strlcpy(cur->f_mntonname, m->mnt_dir, sizeof (cur->f_mntonname));
+ }
+ endmntent(fp);
+
+ return n;
+}
diff --git a/lib/libopenbsd/sys/statfs.c b/lib/libopenbsd/sys/statfs.c
new file mode 100644
index 0000000..2b574b9
--- /dev/null
+++ b/lib/libopenbsd/sys/statfs.c
@@ -0,0 +1,12 @@
+#include <sys/mount.h>
+
+/* sys/mount defines statfs as openbsd_statfs, here i need the original one */
+#undef statfs
+
+int openbsd_statfs(const char *path, struct openbsd_statfs *buf)
+{
+ if (statfs(path, &buf->buf) == -1)
+ return -1;
+
+ return 0;
+}