summaryrefslogtreecommitdiffstats
path: root/contrib/mount/mntent.c
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-05-15 00:15:52 -0700
committerAnand Avati <avati@redhat.com>2014-05-17 11:52:53 -0700
commitaa85de4be3f96a140a69170330293bfdfa3d24e7 (patch)
tree8ae6a10aa4b850492aa3cd109db5150e63aa9667 /contrib/mount/mntent.c
parentf4a391e5a44950b0468af082255b9f5abf52b10b (diff)
contrib: Cross platform fixes after recent commits
- provide a getment_r () version which behaves as re-entrant with some caveats for NetBSD/OSX specific. - some apparent warning issues fixed, always use PRI* format specification avoid using %ld i.e not portable Change-Id: Ib3d1a73b426e38b436b356355b97db0104a1a4a5 BUG: 1089172 Signed-off-by: Harshavardhana <harsha@harshavardhana.net> Reviewed-on: http://review.gluster.org/7722 Reviewed-by: Emmanuel Dreyfus <manu@netbsd.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'contrib/mount/mntent.c')
-rw-r--r--contrib/mount/mntent.c71
1 files changed, 61 insertions, 10 deletions
diff --git a/contrib/mount/mntent.c b/contrib/mount/mntent.c
index 5ab5ac19e84..991e694f1cd 100644
--- a/contrib/mount/mntent.c
+++ b/contrib/mount/mntent.c
@@ -35,7 +35,7 @@
* SUCH DAMAGE.
*/
-#ifdef GF_DARWIN_HOST_OS
+#if defined(GF_DARWIN_HOST_OS) || defined(__NetBSD__)
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
@@ -43,6 +43,12 @@
#include <sys/mount.h>
#include "mntent_compat.h"
+#ifdef __NetBSD__
+typedef struct statvfs gf_statfs_t;
+#else
+typedef struct statfs gf_statfs_t;
+#endif
+
static int pos = -1;
static int mntsize = -1;
static struct mntent _mntent;
@@ -102,23 +108,32 @@ flags2opts (int flags)
if (flags & MNT_ASYNC) res = concatopt(res, "async");
#if !defined(GF_DARWIN_HOST_OS)
if (flags & MNT_NOATIME) res = concatopt(res, "noatime");
+#if !defined(__NetBSD__)
if (flags & MNT_NOCLUSTERR) res = concatopt(res, "noclusterr");
if (flags & MNT_NOCLUSTERW) res = concatopt(res, "noclusterw");
if (flags & MNT_NOSYMFOLLOW) res = concatopt(res, "nosymfollow");
if (flags & MNT_SUIDDIR) res = concatopt(res, "suiddir");
-#endif
+#endif /* !__NetBSD__ */
+#endif /* !GF_DARWIN_HOS_OS */
return res;
}
static struct mntent *
-statfs_to_mntent (struct statfs *mntbuf)
+statfs_to_mntent (gf_statfs_t *mntbuf)
{
static char opts_buf[40], *tmp;
+ int f_flags;
_mntent.mnt_fsname = mntbuf->f_mntfromname;
_mntent.mnt_dir = mntbuf->f_mntonname;
_mntent.mnt_type = mntbuf->f_fstypename;
- tmp = flags2opts (mntbuf->f_flags);
+
+#ifdef __NetBSD__
+ f_flags = mntbuf->f_flag;
+#else
+ f_flags = mntbuf->f_flags;
+#endif
+ tmp = flags2opts (f_flags);
if (tmp) {
opts_buf[sizeof(opts_buf)-1] = '\0';
strncpy (opts_buf, tmp, sizeof(opts_buf)-1);
@@ -134,7 +149,10 @@ statfs_to_mntent (struct statfs *mntbuf)
struct mntent *
getmntent (FILE *fp)
{
- struct statfs *mntbuf;
+ gf_statfs_t *mntbuf;
+
+ if (!fp)
+ return NULL;
if (pos == -1 || mntsize == -1)
mntsize = getmntinfo (&mntbuf, MNT_NOWAIT);
@@ -148,16 +166,49 @@ getmntent (FILE *fp)
return (statfs_to_mntent (&mntbuf[pos]));
}
-/* Dummy functions */
+/*
+ Careful using this function ``buffer`` and ``bufsize`` are
+ ignored since there is no stream with strings to populate
+ them on OSX or NetBSD, if one wishes to populate them then
+ perhaps a new function should be written in this source file
+ which uses 'getmntinfo()' to stringify the mntent's
+*/
+
+struct mntent *getmntent_r (FILE *fp, struct mntent *result,
+ char *buffer, int bufsize)
+{
+ struct mntent *ment = NULL;
+
+ if (!fp)
+ return NULL;
+
+ flockfile (fp);
+ ment = getmntent (fp);
+ memcpy (result, ment, sizeof(*ment));
+ funlockfile (fp);
+
+ return result;
+}
+
FILE *
-setmntent(const char *filename, const char *type)
+setmntent (const char *filename, const char *type)
{
- return (FILE *)0x1;
+ FILE *fp = NULL;
+#ifdef GF_DARWIN_HOST_OS
+ fp = fopen (filename, "w");
+#else
+ fp = fopen (filename, type);
+#endif
+ return fp;
}
int
endmntent (FILE *fp)
{
- return 1;
+ if (fp)
+ fclose (fp);
+
+ return 1; /* endmntent() always returns 1 */
}
-#endif /* GF_DARWIN_HOST_OS */
+
+#endif /* GF_DARWIN_HOST_OS || __NetBSD__ */