lobase

Linux port of OpenBSDs userland.
Log | Files | Refs | README

commit 749df661b7dc961b684129612218f9614f4ff195
parent a5b82394b1c2eaae5aff6854e356e8e453518c8d
Author: Duncaen <mail@duncano.de>
Date:   Tue,  7 Mar 2017 22:56:14 +0100

lib/libopenbsd: add mount path etc to statfs(2) and use getmntinfo cache internally

Diffstat:
lib/libopenbsd/sys/statfs.c | 21++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git 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; }