comparison mercurial/osutil.c @ 31622:2243ba216f66

statfs: change Linux feature detection Previously we check three things: "statfs" function, "linux/magic.h" and "sys/vfs.h" headers. But we didn't check "struct statfs" or the "f_type" field. That means if a system has "statfs" but "struct statfs" is not defined in the two header files we check, or defined without the "f_type" field, the compilation will fail. This patch combines the checks (2 headers + 1 function + 1 field) together and sets "HAVE_LINUX_STATFS". It makes setup.py faster (less checks), and more reliable (immutable to the issue above).
author Jun Wu <quark@fb.com>
date Fri, 24 Mar 2017 14:59:19 -0700
parents 2d501fb60b2d
children a01e1132f6fa
comparison
equal deleted inserted replaced
31621:b26975483841 31622:2243ba216f66
22 #include <dirent.h> 22 #include <dirent.h>
23 #include <sys/socket.h> 23 #include <sys/socket.h>
24 #include <sys/stat.h> 24 #include <sys/stat.h>
25 #include <sys/types.h> 25 #include <sys/types.h>
26 #include <unistd.h> 26 #include <unistd.h>
27 #ifdef HAVE_LINUX_MAGIC_H 27 #ifdef HAVE_LINUX_STATFS
28 #include <linux/magic.h> 28 #include <linux/magic.h>
29 #include <sys/vfs.h>
29 #endif 30 #endif
30 #ifdef HAVE_BSD_STATFS 31 #ifdef HAVE_BSD_STATFS
31 #include <sys/mount.h> 32 #include <sys/mount.h>
32 #include <sys/param.h> 33 #include <sys/param.h>
33 #endif
34 #ifdef HAVE_SYS_VFS_H
35 #include <sys/vfs.h>
36 #endif 34 #endif
37 #endif 35 #endif
38 36
39 #ifdef __APPLE__ 37 #ifdef __APPLE__
40 #include <sys/attr.h> 38 #include <sys/attr.h>
794 792
795 Py_RETURN_NONE; 793 Py_RETURN_NONE;
796 } 794 }
797 #endif /* ndef SETPROCNAME_USE_NONE */ 795 #endif /* ndef SETPROCNAME_USE_NONE */
798 796
799 #ifdef HAVE_STATFS 797 #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS)
800 /* given a directory path, return filesystem type (best-effort), or None */ 798 /* given a directory path, return filesystem type (best-effort), or None */
801 const char *getfstype(const char *path) { 799 const char *getfstype(const char *path) {
802 #ifdef HAVE_BSD_STATFS 800 #ifdef HAVE_BSD_STATFS
803 /* need to return a string field */ 801 /* need to return a string field */
804 static struct statfs buf; 802 static struct statfs buf;
808 int r; 806 int r;
809 memset(&buf, 0, sizeof(buf)); 807 memset(&buf, 0, sizeof(buf));
810 r = statfs(path, &buf); 808 r = statfs(path, &buf);
811 if (r != 0) 809 if (r != 0)
812 return NULL; 810 return NULL;
813 #ifdef HAVE_BSD_STATFS 811 #if defined(HAVE_BSD_STATFS)
814 /* BSD or OSX provides a f_fstypename field */ 812 /* BSD or OSX provides a f_fstypename field */
815 return buf.f_fstypename; 813 return buf.f_fstypename;
816 #endif 814 #elif defined(HAVE_LINUX_STATFS)
817 /* Begin of Linux filesystems */ 815 /* Begin of Linux filesystems */
818 #ifdef ADFS_SUPER_MAGIC 816 #ifdef ADFS_SUPER_MAGIC
819 if (buf.f_type == ADFS_SUPER_MAGIC) 817 if (buf.f_type == ADFS_SUPER_MAGIC)
820 return "adfs"; 818 return "adfs";
821 #endif 819 #endif
1082 #ifdef XFS_SUPER_MAGIC 1080 #ifdef XFS_SUPER_MAGIC
1083 if (buf.f_type == XFS_SUPER_MAGIC) 1081 if (buf.f_type == XFS_SUPER_MAGIC)
1084 return "xfs"; 1082 return "xfs";
1085 #endif 1083 #endif
1086 /* End of Linux filesystems */ 1084 /* End of Linux filesystems */
1085 #endif /* def HAVE_LINUX_STATFS */
1087 return NULL; 1086 return NULL;
1088 } 1087 }
1089 1088
1090 static PyObject *pygetfstype(PyObject *self, PyObject *args) 1089 static PyObject *pygetfstype(PyObject *self, PyObject *args)
1091 { 1090 {
1098 Py_RETURN_NONE; 1097 Py_RETURN_NONE;
1099 1098
1100 PyObject *result = Py_BuildValue("s", type); 1099 PyObject *result = Py_BuildValue("s", type);
1101 return result; 1100 return result;
1102 } 1101 }
1103 #endif /* def HAVE_STATFS */ 1102 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
1104 1103
1105 #endif /* ndef _WIN32 */ 1104 #endif /* ndef _WIN32 */
1106 1105
1107 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) 1106 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
1108 { 1107 {
1276 #endif 1275 #endif
1277 #ifndef SETPROCNAME_USE_NONE 1276 #ifndef SETPROCNAME_USE_NONE
1278 {"setprocname", (PyCFunction)setprocname, METH_VARARGS, 1277 {"setprocname", (PyCFunction)setprocname, METH_VARARGS,
1279 "set process title (best-effort)\n"}, 1278 "set process title (best-effort)\n"},
1280 #endif 1279 #endif
1281 #ifdef HAVE_STATFS 1280 #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS)
1282 {"getfstype", (PyCFunction)pygetfstype, METH_VARARGS, 1281 {"getfstype", (PyCFunction)pygetfstype, METH_VARARGS,
1283 "get filesystem type (best-effort)\n"}, 1282 "get filesystem type (best-effort)\n"},
1284 #endif 1283 #endif
1285 #endif /* ndef _WIN32 */ 1284 #endif /* ndef _WIN32 */
1286 #ifdef __APPLE__ 1285 #ifdef __APPLE__