From: Jan Tulak <jtulak@redhat.com>
To: xfs@oss.sgi.com
Cc: hch@infradead.org, Jan Tulak <jtulak@redhat.com>
Subject: [PATCH 10/11 v2] xfsprogs: make fsr use mntinfo when there is no mntent
Date: Tue, 8 Sep 2015 16:23:27 +0200 [thread overview]
Message-ID: <1441722207-9141-1-git-send-email-jtulak@redhat.com> (raw)
In-Reply-To: <1440590555-20463-10-git-send-email-jtulak@redhat.com>
For what fsr needs, mntinfo can be used instead of mntent.
Custom mntent struct is used to avoid too big ifdefs:
We only change few lines and the rest of the code can still
use mntent as before.
CHANGE
- subject was: "add dummy mntent for OS X"
- reduced the stuby code.
Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
fsr/Makefile | 8 +++++++
fsr/xfs_fsr.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--------
include/darwin.h | 20 ++++++++++++++++
3 files changed, 87 insertions(+), 10 deletions(-)
diff --git a/fsr/Makefile b/fsr/Makefile
index a9d1bf6..d3521b2 100644
--- a/fsr/Makefile
+++ b/fsr/Makefile
@@ -9,6 +9,14 @@ LTCOMMAND = xfs_fsr
CFILES = xfs_fsr.c
LLDLIBS = $(LIBHANDLE)
+ifeq ($(HAVE_GETMNTENT),yes)
+LCFLAGS += -DHAVE_GETMNTENT
+endif
+
+ifeq ($(HAVE_GETMNTINFO),yes)
+LCFLAGS += -DHAVE_GETMNTINFO
+endif
+
default: depend $(LTCOMMAND)
include $(BUILDRULES)
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 5f95cdc..ff791d3 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -32,8 +32,10 @@
#include <sys/statvfs.h>
#include <sys/xattr.h>
-#ifdef HAVE_MNTENT
+#if defined(HAVE_GETMNTENT)
# include <mntent.h>
+#elif defined(HAVE_GETMNTINFO)
+# include <sys/mount.h>
#endif
#ifdef __APPLE__
@@ -191,9 +193,10 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
{
struct mntent *t;
struct stat64 ms;
- FILE *mtabp;
char *mntp = NULL;
+#if defined(HAVE_GETMNTENT)
+ FILE *mtabp;
mtabp = setmntent(mtab, "r");
if (!mtabp) {
fprintf(stderr, _("%s: cannot read %s\n"),
@@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
}
while ((t = getmntent(mtabp))) {
+#elif defined(HAVE_GETMNTINFO)
+ struct statfs *stats;
+ int error, i, count;
+ // because "t" is a pointer, but we don't need to use
+ // malloc for this usage
+ struct mntent t_tmp;
+ t = &t_tmp;
+
+
+ error = 0;
+ if ((count = getmntinfo(&stats, 0)) < 0) {
+ fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
+ progname, strerror(errno));
+ return 0;
+ }
+
+ for (i = 0; i < count; i++) {
+ mntinfo2mntent(&stats[i], t);
+#else
+# error "How do I extract info about mounted filesystems on this platform?"
+#endif
if (S_ISDIR(sb->st_mode)) { /* mount point */
if (stat64(t->mnt_dir, &ms) < 0)
continue;
@@ -233,10 +257,11 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
break;
}
+#if defined(HAVE_GETMNTENT)
endmntent(mtabp);
+#endif
return mntp;
}
-
int
main(int argc, char **argv)
{
@@ -411,18 +436,11 @@ usage(int ret)
static void
initallfs(char *mtab)
{
- FILE *fp;
struct mntent *mp;
int mi;
char *cp;
struct stat64 sb;
- fp = setmntent(mtab, "r");
- if (fp == NULL) {
- fsrprintf(_("could not open mtab file: %s\n"), mtab);
- exit(1);
- }
-
/* malloc a number of descriptors, increased later if needed */
if (!(fsbase = (fsdesc_t *)malloc(fsbufsize * sizeof(fsdesc_t)))) {
fsrprintf(_("out of memory: %s\n"), strerror(errno));
@@ -433,7 +451,36 @@ initallfs(char *mtab)
/* find all rw xfs file systems */
mi = 0;
fs = fsbase;
+
+#if defined(HAVE_GETMNTENT)
+ FILE *fp;
+ fp = setmntent(mtab, "r");
+ if (fp == NULL) {
+ fsrprintf(_("could not open mtab file: %s\n"), mtab);
+ exit(1);
+ }
+
while ((mp = getmntent(fp))) {
+#elif defined(HAVE_GETMNTINFO)
+ struct statfs *stats;
+ int error, i, count;
+ // because "t" is a pointer, but we don't need to use
+ // malloc for this usage
+ struct mntent mp_tmp;
+ mp = &mp_tmp;
+ error = 0;
+ if ((count = getmntinfo(&stats, 0)) < 0) {
+ fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
+ progname, strerror(errno));
+ exit(1);
+ }
+
+ for (i = 0; i < count; i++) {
+ mntinfo2mntent(&stats[i], mp);
+#else
+# error "How do I extract info about mounted filesystems on this platform?"
+#endif
+
int rw = 0;
if (strcmp(mp->mnt_type, MNTTYPE_XFS ) != 0 ||
@@ -485,7 +532,9 @@ initallfs(char *mtab)
}
numfs = mi;
fsend = (fsbase + numfs);
+#if defined(HAVE_GETMNTENT)
endmntent(fp);
+#endif
if (numfs == 0) {
fsrprintf(_("no rw xfs file systems in mtab: %s\n"), mtab);
exit(0);
diff --git a/include/darwin.h b/include/darwin.h
index 288ad1f..0313f46 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -218,7 +218,27 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
/* FSR */
+# include <sys/mount.h>
+# include <sys/param.h>
+#include <sys/ucred.h>
+#include <errno.h>
#define statvfs64 statfs
#define _PATH_MOUNTED "/etc/mtab"
+struct mntent
+{
+ char *mnt_fsname;
+ char *mnt_dir;
+ char *mnt_type;
+ char *mnt_opts;
+ int mnt_freq;
+ int mnt_passno;
+};
+
+static inline void mntinfo2mntent (struct statfs * stats, struct mntent * mnt) {
+ mnt->mnt_fsname = stats->f_mntfromname;
+ mnt->mnt_dir = stats->f_mntonname;
+ mnt->mnt_type = stats->f_fstypename;
+}
+
#endif /* __XFS_DARWIN_H__ */
--
2.4.5
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2015-09-08 14:23 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-26 12:00 [PATCH 00/11 v4] xfsprogs: Partial OSX support Jan Tulak
2015-08-26 12:02 ` [PATCH 01/11] xfsprogs: Add a way to compile without blkid Jan Tulak
2015-08-26 12:02 ` [PATCH 02/11] xfsprogs: avoid dependency on linux XATTR_SIZE/LIST_MAX Jan Tulak
2015-08-26 22:01 ` Dave Chinner
2015-08-27 6:06 ` Jan Tulak
2015-08-27 6:02 ` Jan Tulak
2015-09-03 10:33 ` [PATCH 02a/11] xfsprogs: Add XATTR_LIST_MAX to OS X headers Jan Tulak
2015-09-03 10:33 ` [PATCH 02b/11] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX Jan Tulak
2015-09-03 10:33 ` [PATCH 02c/11] xfsprogs: prefix XATTR_LIST_MAX with XFS_ Jan Tulak
2015-08-31 18:58 ` [PATCH 02/11] xfsprogs: avoid dependency on linux XATTR_SIZE/LIST_MAX Christoph Hellwig
2015-09-01 8:13 ` Jan Tulak
2015-09-01 8:35 ` Jan Tulak
2015-08-26 12:02 ` [PATCH 03/11] xfsprogs: Add includes required for OS X builds (delta) Jan Tulak
2015-08-31 18:58 ` Christoph Hellwig
2015-08-26 12:02 ` [PATCH 04/11] xfsprogs: Add autoconf check for fsetxattr call Jan Tulak
2015-08-31 18:59 ` Christoph Hellwig
2015-08-26 12:02 ` [PATCH 05/11] xfsprogs: uuid changes for OS X Jan Tulak
2015-08-31 18:59 ` Christoph Hellwig
2015-08-26 12:02 ` [PATCH 06/11] xfsprogs: Remove conflicting define " Jan Tulak
2015-08-31 18:59 ` Christoph Hellwig
2015-08-26 12:02 ` [PATCH 07/11] xfsprogs: add nftw64 translation " Jan Tulak
2015-08-31 18:59 ` Christoph Hellwig
2015-09-01 7:49 ` Jan Tulak
2015-09-01 8:04 ` [PATCH v2] " Jan Tulak
2015-09-01 16:31 ` Darrick J. Wong
2015-09-01 17:24 ` Christoph Hellwig
2015-09-02 7:12 ` Jan Tulak
2015-09-03 10:39 ` [PATCH v2 07/11] xfsprogs: change nftw64 to nftw Jan Tulak
2015-09-09 10:11 ` Jan Tulak
2015-09-09 10:14 ` [PATCH v3 " Jan Tulak
2015-08-26 12:02 ` [PATCH 08/11] xfsprogs: Add a timer implementation for OS X Jan Tulak
2015-08-31 19:00 ` Christoph Hellwig
2015-09-02 10:54 ` Jan Tulak
2015-08-26 12:02 ` [PATCH 09/11] xfsprogs: Add statvfs64 for osx Jan Tulak
2015-09-08 14:24 ` [PATCH 09/11 v2] " Jan Tulak
2015-08-26 12:02 ` [PATCH 10/11] xfsprogs: add dummy mntent for OS X Jan Tulak
2015-08-31 19:01 ` Christoph Hellwig
2015-09-03 9:01 ` Jan Tulak
2015-09-03 10:33 ` Dave Chinner
2015-09-03 10:37 ` Jan Tulak
2015-09-08 14:23 ` Jan Tulak [this message]
2015-08-26 12:02 ` [PATCH 11/11] xfsprogs: add dummy mremap " Jan Tulak
2015-08-31 19:01 ` Christoph Hellwig
2015-09-03 10:35 ` [PATCH v2] xfsprogs: Make mremap conditional Jan Tulak
2015-08-31 18:57 ` [PATCH 01/11] xfsprogs: Add a way to compile without blkid Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1441722207-9141-1-git-send-email-jtulak@redhat.com \
--to=jtulak@redhat.com \
--cc=hch@infradead.org \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox