diff --git a/mercurial/osutil.c b/mercurial/osutil.c --- a/mercurial/osutil.c +++ b/mercurial/osutil.c @@ -24,16 +24,14 @@ #include #include #include -#ifdef HAVE_LINUX_MAGIC_H +#ifdef HAVE_LINUX_STATFS #include +#include #endif #ifdef HAVE_BSD_STATFS #include #include #endif -#ifdef HAVE_SYS_VFS_H -#include -#endif #endif #ifdef __APPLE__ @@ -796,7 +794,7 @@ static PyObject *setprocname(PyObject *s } #endif /* ndef SETPROCNAME_USE_NONE */ -#ifdef HAVE_STATFS +#if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) /* given a directory path, return filesystem type (best-effort), or None */ const char *getfstype(const char *path) { #ifdef HAVE_BSD_STATFS @@ -810,10 +808,10 @@ const char *getfstype(const char *path) r = statfs(path, &buf); if (r != 0) return NULL; -#ifdef HAVE_BSD_STATFS +#if defined(HAVE_BSD_STATFS) /* BSD or OSX provides a f_fstypename field */ return buf.f_fstypename; -#endif +#elif defined(HAVE_LINUX_STATFS) /* Begin of Linux filesystems */ #ifdef ADFS_SUPER_MAGIC if (buf.f_type == ADFS_SUPER_MAGIC) @@ -1084,6 +1082,7 @@ const char *getfstype(const char *path) return "xfs"; #endif /* End of Linux filesystems */ +#endif /* def HAVE_LINUX_STATFS */ return NULL; } @@ -1100,7 +1099,7 @@ static PyObject *pygetfstype(PyObject *s PyObject *result = Py_BuildValue("s", type); return result; } -#endif /* def HAVE_STATFS */ +#endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */ #endif /* ndef _WIN32 */ @@ -1278,7 +1277,7 @@ static PyMethodDef methods[] = { {"setprocname", (PyCFunction)setprocname, METH_VARARGS, "set process title (best-effort)\n"}, #endif -#ifdef HAVE_STATFS +#if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) {"getfstype", (PyCFunction)pygetfstype, METH_VARARGS, "get filesystem type (best-effort)\n"}, #endif diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -591,24 +591,21 @@ osutil_cflags = [] osutil_ldflags = [] # platform specific macros -for plat, func in [('bsd', 'setproctitle'), ('bsd|darwin|linux', 'statfs')]: +for plat, func in [('bsd', 'setproctitle')]: if re.search(plat, sys.platform) and hasfunction(new_compiler(), func): osutil_cflags.append('-DHAVE_%s' % func.upper()) -for plat, header in [ - ('linux', 'linux/magic.h'), - ('linux', 'sys/vfs.h'), -]: - if re.search(plat, sys.platform) and hasheader(new_compiler(), header): - macro = header.replace('/', '_').replace('.', '_').upper() - osutil_cflags.append('-DHAVE_%s' % macro) - for plat, macro, code in [ ('bsd|darwin', 'BSD_STATFS', ''' #include #include int main() { struct statfs s; return sizeof(s.f_fstypename); } '''), + ('linux', 'LINUX_STATFS', ''' + #include + #include + int main() { struct statfs s; return sizeof(s.f_type); } + '''), ]: if re.search(plat, sys.platform) and cancompile(new_compiler(), code): osutil_cflags.append('-DHAVE_%s' % macro)