aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-03-07 22:56:14 +0100
committerDuncaen <mail@duncano.de>2017-03-07 22:57:45 +0100
commit749df661b7dc961b684129612218f9614f4ff195 (patch)
tree1498e9d98912576e90879f48a99f4ddedd61368c
parenta5b82394b1c2eaae5aff6854e356e8e453518c8d (diff)
downloadlobase-749df661b7dc961b684129612218f9614f4ff195.tar.gz
lib/libopenbsd: add mount path etc to statfs(2) and use getmntinfo cache internally
-rw-r--r--lib/libopenbsd/sys/statfs.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/libopenbsd/sys/statfs.c b/lib/libopenbsd/sys/statfs.c
index 2b574b9..9d43963 100644
--- a/lib/libopenbsd/sys/statfs.c
+++ b/lib/libopenbsd/sys/statfs.c
@@ -1,12 +1,31 @@
#include <sys/mount.h>
+#include <sys/stat.h>
+#include <string.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)
+ struct statfs sfb;
+ struct stat sb;
+ struct openbsd_statfs *mntbuf;
+ int num, i;
+
+ if (stat(path, &sb) == -1)
+ return -1;
+
+ if (!(num = getmntinfo(&mntbuf, MNT_WAIT)))
return -1;
+ for (i = 0; i <= num; i++)
+ if (mntbuf[i].st_dev == sb.st_dev) {
+ if (statfs(path, &sfb) == -1)
+ return -1;
+ memcpy(&mntbuf[i].buf, &sfb, sizeof sfb);
+ memcpy(buf, &mntbuf[i], sizeof (struct openbsd_statfs));
+ break;
+ }
+
return 0;
}