[PATCH 5 of 5] osutil: implement getfsmountpoint() on BSD systems

Matt Harbison mharbison72 at gmail.com
Sat Dec 30 01:37:34 EST 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1514609752 18000
#      Fri Dec 29 23:55:52 2017 -0500
# Node ID 91eb2a6192382543f57d93404b0252e30a1a41ab
# Parent  b02665ecb0c1653ace0ac1ed7812ffd42317fb43
osutil: implement getfsmountpoint() on BSD systems

I don't have a BSD system handy to test this, but it looks simple enough from
the man page.

diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c
--- a/mercurial/cext/osutil.c
+++ b/mercurial/cext/osutil.c
@@ -1112,6 +1112,24 @@
 }
 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
 
+#if defined(HAVE_BSD_STATFS)
+static PyObject *getfsmountpoint(PyObject *self, PyObject *args)
+/* given a directory path, return filesystem mount point (best-effort) */
+{
+	const char *path = NULL;
+	struct statfs buf;
+	int r;
+	if (!PyArg_ParseTuple(args, "s", &path))
+		return NULL;
+
+	memset(&buf, 0, sizeof(buf));
+	r = statfs(path, &buf);
+	if (r != 0)
+		return PyErr_SetFromErrno(PyExc_OSError);
+	return Py_BuildValue("s", buf.f_mntonname);
+}
+#endif /* defined(HAVE_BSD_STATFS) */
+
 static PyObject *unblocksignal(PyObject *self, PyObject *args)
 {
 	int sig = 0;
@@ -1416,7 +1434,7 @@
 	{"getfstype", (PyCFunction)getfstype, METH_VARARGS,
 	 "get filesystem type (best-effort)\n"},
 #endif
-#if defined(_WIN32)
+#if defined(HAVE_BSD_STATFS) || defined(_WIN32)
 	{"getfsmountpoint", (PyCFunction)getfsmountpoint, METH_VARARGS,
 	 "get filesystem mount point (best-effort)\n"},
 #endif


More information about the Mercurial-devel mailing list