Bug 11923 - System.IO.DriveInfo.GetDrives() returns a single null drive
Summary: System.IO.DriveInfo.GetDrives() returns a single null drive
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-23 19:31 UTC by Andrew Barnes
Modified: 2014-07-17 08:00 UTC (History)
2 users (show)

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


Attachments
Test Case (1.08 KB, text/x-csharp)
2013-04-23 19:31 UTC, Andrew Barnes
Details

Description Andrew Barnes 2013-04-23 19:31:12 UTC
Created attachment 3860 [details]
Test Case

Running System.IO.DriveInfo.GetDrives() on my system returns a single drive, with Name.Length == 0 accessing most properties causes an exception:

Test case output:

$ mono ./DriveInfoTest.exe
Drive: 

Unhandled Exception:
System.ArgumentException: An empty file name is not valid.
  at System.IO.FileSystemInfo.CheckPath (System.String path) [0x00000] in <filename unknown>:0 
  at System.IO.DirectoryInfo..ctor (System.String path, Boolean simpleOriginalPath) [0x00000] in <filename unknown>:0 
  at System.IO.DirectoryInfo..ctor (System.String path) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:.ctor (string)
  at System.IO.DriveInfo.get_RootDirectory () [0x00000] in <filename unknown>:0 
  at Test.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: An empty file name is not valid.
  at System.IO.FileSystemInfo.CheckPath (System.String path) [0x00000] in <filename unknown>:0 
  at System.IO.DirectoryInfo..ctor (System.String path, Boolean simpleOriginalPath) [0x00000] in <filename unknown>:0 
  at System.IO.DirectoryInfo..ctor (System.String path) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:.ctor (string)
  at System.IO.DriveInfo.get_RootDirectory () [0x00000] in <filename unknown>:0 
  at Test.Main () [0x00000] in <filename unknown>:0 

Expected output:

$ mono ./DriveInfoTest.exe
Drive: /
Drive.RootDirectory: /
  File type: Unknown
  Volume label: /
  File system: 
  Available space to current user:   336752803840 bytes
  Total available space:             336752803840 bytes
  Total size of drive:               367505702912 bytes 
Drive: /run
Drive.RootDirectory: /run
  File type: Ram
  Volume label: /run
  File system: tmpfs
  Available space to current user:     8411750400 bytes
  Total available space:               8411750400 bytes
  Total size of drive:                 8413601792 bytes 

  ... Many more here ...

Drive.RootDirectory: /systems/virtuals/ovirt
  File type: Unknown
  Volume label: /systems/virtuals/ovirt
  File system: 
  Available space to current user:   336752803840 bytes
  Total available space:             336752803840 bytes
  Total size of drive:               348727934976 bytes 
Drive: /proc/sys/fs/binfmt_misc
Drive.RootDirectory: /proc/sys/fs/binfmt_misc
  File type: Unknown
  Volume label: /proc/sys/fs/binfmt_misc
  File system: 
  Available space to current user:              0 bytes
  Total available space:                        0 bytes
  Total size of drive:                          0 bytes 
Drive: /var/lib/nfs/rpc_pipefs
Drive.RootDirectory: /var/lib/nfs/rpc_pipefs
  File type: Unknown
  Volume label: /var/lib/nfs/rpc_pipefs
  File system: 
  Available space to current user:              0 bytes
  Total available space:                        0 bytes
  Total size of drive:                          0 bytes 
Drive: /proc/fs/nfsd
Drive.RootDirectory: /proc/fs/nfsd
  File type: Unknown
  Volume label: /proc/fs/nfsd
  File system: 
  Available space to current user:              0 bytes
  Total available space:                        0 bytes
  Total size of drive:                          0 bytes 
Total drives: 120

I performed some debugging and come up with the following patch which gives me the expected output:

Not sure if I am missing something here but the ignore_entry logic looks a little aggressive.

diff --git a/mono/io-layer/io.c b/mono/io-layer/io.c
index 579c48d..f354f72 100755
--- a/mono/io-layer/io.c
+++ b/mono/io-layer/io.c
@@ -3726,7 +3726,7 @@ add_drive_string (guint32 len, gunichar2 *buf, LinuxMountInfoParseState *state)
                else
                        ignore_entry = FALSE;
        } else
-               ignore_entry = TRUE;
+               ignore_entry = FALSE;
 
        if (!ignore_entry) {
                gunichar2 *dir;


Some details on my environment are:

$ uname -a
Linux b1 3.7.9+ #10 SMP Mon Mar 18 15:41:36 EST 2013 x86_64 AMD Phenom(tm) II X6 1100T Processor AuthenticAMD GNU/Linux
$ cat /proc/self/mountinfo | grep none       
15 18 0:3 / /proc rw,relatime - proc none rw
$ cat /proc/self/mountinfo| wc -l    
121
Comment 1 Andrew Barnes 2013-04-23 19:31:50 UTC
Mono version: 3.0.7

Note You need to log in before you can comment on or make changes to this bug.