Patchwork [2,of,3] osutil: report fstype for BSD and OSX

login
register
mail settings
Submitter Jun Wu
Date March 24, 2017, 5:32 a.m.
Message ID <825bb185512c66a43ae6.1490333573@localhost.localdomain>
Download mbox | patch
Permalink /patch/19623/
State Accepted
Headers show

Comments

Jun Wu - March 24, 2017, 5:32 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1490332382 25200
#      Thu Mar 23 22:13:02 2017 -0700
# Node ID 825bb185512c66a43ae6927933196b8356c99798
# Parent  597a29c947fe2b9f9ac0a6a03cf710ab9f69757c
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 825bb185512c
osutil: report fstype for BSD and OSX
Yuya Nishihara - March 24, 2017, 2:39 p.m.
On Thu, 23 Mar 2017 22:32:53 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1490332382 25200
> #      Thu Mar 23 22:13:02 2017 -0700
> # Node ID 825bb185512c66a43ae6927933196b8356c99798
> # Parent  597a29c947fe2b9f9ac0a6a03cf710ab9f69757c
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 825bb185512c
> osutil: report fstype for BSD and OSX
> 
> diff --git a/mercurial/osutil.c b/mercurial/osutil.c
> --- a/mercurial/osutil.c
> +++ b/mercurial/osutil.c
> @@ -28,8 +28,6 @@
>  #include <linux/magic.h>
>  #endif
> -#ifdef HAVE_SYS_MOUNT_H
> +#ifdef HAVE_BSD_STATFS
>  #include <sys/mount.h>
> -#endif
> -#ifdef HAVE_SYS_PARAM_H
>  #include <sys/param.h>
>  #endif
> @@ -802,5 +800,10 @@ static PyObject *setprocname(PyObject *s
>  /* given a directory path, return filesystem type (best-effort), or None */
>  const char *getfstype(const char *path) {
> +#ifdef HAVE_BSD_STATFS
> +	/* need to return a string field */
> +	static struct statfs buf;
> +#else
>  	struct statfs buf;
> +#endif

Nit: I prefer moving the stack allocation of struct statfs to caller. We might
blindly port getfstype() to cffi module and get in trouble due to the static
storage.

Patch

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -28,8 +28,6 @@ 
 #include <linux/magic.h>
 #endif
-#ifdef HAVE_SYS_MOUNT_H
+#ifdef HAVE_BSD_STATFS
 #include <sys/mount.h>
-#endif
-#ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
@@ -802,5 +800,10 @@  static PyObject *setprocname(PyObject *s
 /* given a directory path, return filesystem type (best-effort), or None */
 const char *getfstype(const char *path) {
+#ifdef HAVE_BSD_STATFS
+	/* need to return a string field */
+	static struct statfs buf;
+#else
 	struct statfs buf;
+#endif
 	int r;
 	memset(&buf, 0, sizeof(buf));
@@ -808,4 +811,8 @@  const char *getfstype(const char *path) 
 	if (r != 0)
 		return NULL;
+#ifdef HAVE_BSD_STATFS
+	/* BSD or OSX provides a f_fstypename field */
+	return buf.f_fstypename;
+#endif
 	/* Begin of Linux filesystems */
 #ifdef ADFS_SUPER_MAGIC