##// END OF EJS Templates
statfs: refactor inner function as a mapping from statfs to string...
Yuya Nishihara -
r31676:f7aeb1f4 default
parent child Browse files
Show More
@@ -794,18 +794,15 b' static PyObject *setprocname(PyObject *s'
794 }
794 }
795 #endif /* ndef SETPROCNAME_USE_NONE */
795 #endif /* ndef SETPROCNAME_USE_NONE */
796
796
797 #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS)
798 /* given a directory path and a zero-initialized statfs buffer, return
799 * filesystem type name (best-effort), or NULL. */
800 const char *getfstype(const char *path, struct statfs *pbuf) {
801 int r;
802 r = statfs(path, pbuf);
803 if (r != 0)
804 return NULL;
805 #if defined(HAVE_BSD_STATFS)
797 #if defined(HAVE_BSD_STATFS)
798 static const char *describefstype(const struct statfs *pbuf)
799 {
806 /* BSD or OSX provides a f_fstypename field */
800 /* BSD or OSX provides a f_fstypename field */
807 return pbuf->f_fstypename;
801 return pbuf->f_fstypename;
802 }
808 #elif defined(HAVE_LINUX_STATFS)
803 #elif defined(HAVE_LINUX_STATFS)
804 static const char *describefstype(const struct statfs *pbuf)
805 {
809 /* Begin of Linux filesystems */
806 /* Begin of Linux filesystems */
810 #ifdef ADFS_SUPER_MAGIC
807 #ifdef ADFS_SUPER_MAGIC
811 if (pbuf->f_type == ADFS_SUPER_MAGIC)
808 if (pbuf->f_type == ADFS_SUPER_MAGIC)
@@ -1092,19 +1089,25 b' const char *getfstype(const char *path, '
1092 return "xfs";
1089 return "xfs";
1093 #endif
1090 #endif
1094 /* End of Linux filesystems */
1091 /* End of Linux filesystems */
1095 #endif /* def HAVE_LINUX_STATFS */
1096 return NULL;
1092 return NULL;
1097 }
1093 }
1094 #endif /* def HAVE_LINUX_STATFS */
1098
1095
1096 #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS)
1097 /* given a directory path, return filesystem type name (best-effort) */
1099 static PyObject *pygetfstype(PyObject *self, PyObject *args)
1098 static PyObject *pygetfstype(PyObject *self, PyObject *args)
1100 {
1099 {
1101 const char *path = NULL;
1100 const char *path = NULL;
1102 struct statfs buf;
1101 struct statfs buf;
1102 int r;
1103 if (!PyArg_ParseTuple(args, "s", &path))
1103 if (!PyArg_ParseTuple(args, "s", &path))
1104 return NULL;
1104 return NULL;
1105
1105
1106 memset(&buf, 0, sizeof(buf));
1106 memset(&buf, 0, sizeof(buf));
1107 return Py_BuildValue("s", getfstype(path, &buf));
1107 r = statfs(path, &buf);
1108 if (r != 0)
1109 Py_RETURN_NONE;
1110 return Py_BuildValue("s", describefstype(&buf));
1108 }
1111 }
1109 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
1112 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
1110
1113
General Comments 0
You need to be logged in to leave comments. Login now