[runtime] Use statfs(2) on Android.
authorJonathan Pryor <jonpryor@vt.edu>
Wed, 17 Sep 2014 16:56:44 +0000 (12:56 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Wed, 17 Sep 2014 16:56:44 +0000 (12:56 -0400)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=23077

Reverts commit 53ce92470.

Commit 53ce92470 disabled use of statfs(2) on Android, for unspecified
reasons. (My *suspicion* is that the Android version mono was
originally ported to didn't have statfs(2), but I can neither confirm
nor deny that guess.)

Android has supported statfs(2) since API-4 Android v1.6 (in that
statfs(2) is in the header files); what's missing is MNT_RDONLY. What
IS present is MS_RDONLY, which appears to serve the same purpose.

Re-enable use of statfs(2) and use MS_RDONLY when building against the
Android NDK.

mono/io-layer/io.c

index 169cb07617adb06ac4bcb88ea5cc6fd59adad7b6..03672d4197efd1f5439337d506be2a9cdb2a815e 100644 (file)
@@ -3904,7 +3904,7 @@ GetLogicalDriveStrings_Mtab (guint32 len, gunichar2 *buf)
 }
 #endif
 
-#if (defined(HAVE_STATVFS) || defined(HAVE_STATFS)) && !defined(PLATFORM_ANDROID)
+#if defined(HAVE_STATVFS) || defined(HAVE_STATFS)
 gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_bytes_avail,
                            WapiULargeInteger *total_number_of_bytes,
                            WapiULargeInteger *total_number_of_free_bytes)
@@ -3943,7 +3943,11 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_
                block_size = fsstat.f_frsize;
 #elif defined(HAVE_STATFS)
                ret = statfs (utf8_path_name, &fsstat);
+#if defined (MNT_RDONLY)
                isreadonly = ((fsstat.f_flags & MNT_RDONLY) == MNT_RDONLY);
+#elif defined (MS_RDONLY)
+               isreadonly = ((fsstat.f_flags & MS_RDONLY) == MS_RDONLY);
+#endif
                block_size = fsstat.f_bsize;
 #endif
        } while(ret == -1 && errno == EINTR);