Bug 23077 - Wrap DriveInfo to StatFs
Summary: Wrap DriveInfo to StatFs
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.18.0
Hardware: PC Mac OS
: --- enhancement
Target Milestone: 5.1
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-09-16 23:08 UTC by Cody Beyer (MSFT)
Modified: 2015-05-05 08:22 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample App (31.57 KB, application/zip)
2014-12-01 11:25 UTC, Udham Singh
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Cody Beyer (MSFT) 2014-09-16 23:08:35 UTC
We would like to allow a user to use the generic DriveInfo class to get space information and other information about the system drives on mobile systems. Currently, if you call TotalFreeSpace from driveinfo() you get max int64 returned. 

For example:

foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady)
{
var freetest = drive.TotalFreeSpace;
}
}

sets freetest = '9223372036854775807'

where as

StatFs stat = new StatFs(Android.OS.Environment.ExternalStorageDirectory.ToString());

var freeSpace = stat.TotalBytes

Returns the free space
Comment 2 Jonathan Pryor 2014-09-17 11:51:26 UTC
DriveInfo.TotalFreeSpace is long.MaxValue because Xamarin.Android isn't using a statfs(2)-based GetDiskFreeSpaceEx(); instead it's using a "stub" GetDiskFreeSpaceEx():

https://github.com/mono/mono/blob/ee230d06/mono/io-layer/io.c#L3907
https://github.com/mono/mono/blob/ee230d06/mono/io-layer/io.c#L3987

This change was done in:

https://github.com/mono/mono/commit/53ce92470

I *suspect* that this was done because the above commit is from 2009-Jan-18, while the first Android release to support statfs(2) is API-4 Android v1.6, which was released on 2009-Sep-15, so this change would have been required to to enable running mono on API <= 3.

Given that Xamarin.Android only supports API-4+, it should be possible to revert mono/53ce92470 and use statfs(2). We'll look into doing this for a future release.
Comment 3 Jonathan Pryor 2014-09-17 13:07:26 UTC
Fixed in mono/818b81ef and monodroid/afc96c48.
Comment 4 Udham Singh 2014-12-01 11:25:19 UTC
Created attachment 8921 [details]
Sample App

I have checked this issue and observed that if we call TotalFreeSpace from driveinfo() then it does not return max int64. I am getting the below outputs ;

For device : https://gist.github.com/Rajneesh360Logica/2f8f0f395f196972861f
For Emulator : https://gist.github.com/Rajneesh360Logica/b6631bf397671604db13

I am attaching a sample app which I have created to verify this issue by implementing the code provided in bug description.

Screencast : http://www.screencast.com/t/ov5lpsGTDm2o

Please let me know if I have to check anything else to verify this issue.

Thanks

Environment Info :

=== Xamarin Studio ===

Version 5.7 (build 596)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.12.0 ((detached/b75fa2b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000046

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.6.0.5 (Business Edition)
Hash: 880cc21
Branch: 
Build date: 2014-11-25 12:12:17-0500

=== Xamarin.Android ===

Version: 5.0.0.0 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 507000596
Git revision: d996e9ba6874a0d64241e43e5e6b06322ce29c84
Build date: 2014-11-25 17:17:54-05
Xamarin addins: 8ca19707b41536a391f53364ee4ff9272711feb0

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 5 Jonathan Pryor 2014-12-19 12:50:17 UTC
> I have checked this issue and observed that if we call TotalFreeSpace from
> driveinfo() then it does not return max int64. I am getting the below outputs ;

Correct; you *shouldn't* be getting long.MaxValue from TotalFreeSpace any more.

> Please let me know if I have to check anything else to verify this issue.

Please run `adb shell df` and ensure that the output from df(1) matches the TotalFreeSpace output your app generates.
Comment 6 Parmendra Kumar 2015-05-05 08:22:11 UTC
I have run the 'adb shell df' and the output from df(1) matches the TotalFreeSpace output your app generates.

Screencast: http://www.screencast.com/t/KvZpyGStigw

Hence closing this issue.

Environment info:

Xamarin Studio 5.9 (build 457)
Xcode 6.2 (6776)
Xamarin.Android : 5.1.0.77 (Enterprise Edition)
Operating System Mac OS X 10.9.4