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

Matt Harbison mharbison72 at gmail.com
Sat Dec 30 23:11:14 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 cd1a6de41b08fa43d20aab4636d4802c2055b368
# Parent  d2295086b157c2293d5585fff30df9385d6cb36a
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;
@@ -1311,6 +1329,10 @@
 	{"getfstype", (PyCFunction)getfstype, METH_VARARGS,
 	 "get filesystem type (best-effort)\n"},
 #endif
+#if defined(HAVE_BSD_STATFS)
+	{"getfsmountpoint", (PyCFunction)getfsmountpoint, METH_VARARGS,
+	 "get filesystem mount point (best-effort)\n"},
+#endif
 	{"unblocksignal", (PyCFunction)unblocksignal, METH_VARARGS,
 	 "change signal mask to unblock a given signal\n"},
 #endif /* ndef _WIN32 */
@@ -1323,7 +1345,7 @@
 	{NULL, NULL}
 };
 
-static const int version = 2;
+static const int version = 3;
 
 #ifdef IS_PY3K
 static struct PyModuleDef osutil_module = {
diff --git a/mercurial/policy.py b/mercurial/policy.py
--- a/mercurial/policy.py
+++ b/mercurial/policy.py
@@ -74,7 +74,7 @@
     (r'cext', r'bdiff'): 1,
     (r'cext', r'diffhelpers'): 1,
     (r'cext', r'mpatch'): 1,
-    (r'cext', r'osutil'): 2,
+    (r'cext', r'osutil'): 3,
     (r'cext', r'parsers'): 4,
 }
 


More information about the Mercurial-devel mailing list