##// END OF EJS Templates
statfs: change Linux feature detection...
Jun Wu -
r31622:2243ba21 default
parent child Browse files
Show More
@@ -24,16 +24,14 b''
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 #endif
34 #ifdef HAVE_SYS_VFS_H
35 #include <sys/vfs.h>
36 #endif
37 #endif
35 #endif
38
36
39 #ifdef __APPLE__
37 #ifdef __APPLE__
@@ -796,7 +794,7 b' static PyObject *setprocname(PyObject *s'
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
@@ -810,10 +808,10 b' const char *getfstype(const char *path) '
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)
@@ -1084,6 +1082,7 b' const char *getfstype(const char *path) '
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
@@ -1100,7 +1099,7 b' static PyObject *pygetfstype(PyObject *s'
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
@@ -1278,7 +1277,7 b' static PyMethodDef methods[] = {'
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
@@ -591,24 +591,21 b' osutil_cflags = []'
591 osutil_ldflags = []
591 osutil_ldflags = []
592
592
593 # platform specific macros
593 # platform specific macros
594 for plat, func in [('bsd', 'setproctitle'), ('bsd|darwin|linux', 'statfs')]:
594 for plat, func in [('bsd', 'setproctitle')]:
595 if re.search(plat, sys.platform) and hasfunction(new_compiler(), func):
595 if re.search(plat, sys.platform) and hasfunction(new_compiler(), func):
596 osutil_cflags.append('-DHAVE_%s' % func.upper())
596 osutil_cflags.append('-DHAVE_%s' % func.upper())
597
597
598 for plat, header in [
599 ('linux', 'linux/magic.h'),
600 ('linux', 'sys/vfs.h'),
601 ]:
602 if re.search(plat, sys.platform) and hasheader(new_compiler(), header):
603 macro = header.replace('/', '_').replace('.', '_').upper()
604 osutil_cflags.append('-DHAVE_%s' % macro)
605
606 for plat, macro, code in [
598 for plat, macro, code in [
607 ('bsd|darwin', 'BSD_STATFS', '''
599 ('bsd|darwin', 'BSD_STATFS', '''
608 #include <sys/param.h>
600 #include <sys/param.h>
609 #include <sys/mount.h>
601 #include <sys/mount.h>
610 int main() { struct statfs s; return sizeof(s.f_fstypename); }
602 int main() { struct statfs s; return sizeof(s.f_fstypename); }
611 '''),
603 '''),
604 ('linux', 'LINUX_STATFS', '''
605 #include <linux/magic.h>
606 #include <sys/vfs.h>
607 int main() { struct statfs s; return sizeof(s.f_type); }
608 '''),
612 ]:
609 ]:
613 if re.search(plat, sys.platform) and cancompile(new_compiler(), code):
610 if re.search(plat, sys.platform) and cancompile(new_compiler(), code):
614 osutil_cflags.append('-DHAVE_%s' % macro)
611 osutil_cflags.append('-DHAVE_%s' % macro)
General Comments 0
You need to be logged in to leave comments. Login now