lobase

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

commit e911399a7dba86e47e653f00d42359c8039c4c93
parent 1b8815c48e703ed91d754f77170d7cacd777bd5b
Author: Duncaen <mail@duncano.de>
Date:   Tue,  7 Mar 2017 20:56:56 +0100

lib/libopenbsd: add poor mans statfs and getfsstat compatibility

Diffstat:
include/sys/mount.h | 40++++++++++++++++++++++++++++++++++++++++
lib/libopenbsd/Makefile | 5+++++
lib/libopenbsd/statfs.c | 7-------
lib/libopenbsd/sys/getfsstat.c | 41+++++++++++++++++++++++++++++++++++++++++
lib/libopenbsd/sys/statfs.c | 12++++++++++++
5 files changed, 98 insertions(+), 7 deletions(-)

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