[Mono-list] Simple code - differences in output between mono & .Net

Jonathan Stowe gellyfish@gellyfish.com
Wed, 03 Mar 2004 16:13:40 +0000


On Wed, 2004-03-03 at 15:13, jonathan.cooper@syntegra.com wrote:
> I would assume that the GetLogicalDrives() method on linux would
> require returning the mount points, as these can then be enumerated as
> necessary - for e.g. /dev/cdrom, /dev/usbdrive etc. This approach
> seems much more usable from a development perspective than just
> returning the root.

This could be as simple as this:

using System;
using System.IO;
using System.Collections;

class Test
{

   public static string[] GetLogicalDrives ()
   { 
       string[] drives;

       if ((int)Environment.OSVersion.Platform == 128)
       {
          string line;
          StreamReader mtab = new StreamReader("/etc/mtab");

          ArrayList stuff = new ArrayList();
          string[] fields;
          while ( (line = mtab.ReadLine()) != null )
          {
             fields = line.Split(new char[]{' '});
             if (fields[0] != "none")
             {
                stuff.Add(fields[1]);
             }
          }

          drives = new string[stuff.Count];
          stuff.CopyTo(drives);
       }
       else
       {
          drives = new string [] { "A:\\", "C:\\" };
       }

       return drives;
    }

    public static void Main()
    {
       foreach ( string drive in GetLogicalDrives() )
       {
          Console.WriteLine(drive);
       }
    }
}


>         -----Original Message-----
>         From: Nick Berardi [mailto:nberardi@zigamorph.com] 
>         Sent: 03 March 2004 15:11
>         To: COOPER, Jonathan -Syntegra UK; mono-list@lists.ximian.com
>         Subject: RE: [Mono-list] Simple code - differences in output
>         between mono & .Net
>         
>         
>         
>         I guess logical drives in Linux is just the root.  But I would
>         think that they would include the mount points in here?  Don’t
>         you think?  Because basically that is all that a Windows Drive
>         is.  A mounted partition.
>         
>          
>         
>         Anybody on the list disagree?
>         
>          
>         
>                                        
>         ______________________________________________________________
>         
>         From: jonathan.cooper@syntegra.com
>         [mailto:jonathan.cooper@syntegra.com] 
>         Sent: Wednesday, March 03, 2004 9:57 AM
>         To: nberardi@zigamorph.com; mono-list@lists.ximian.com
>         Subject: RE: [Mono-list] Simple code - differences in output
>         between mono & .Net
>         
>         
>          
>         
>         Ah, that would explain it.
>         
>         
>          
>         
>         
>         Shall I continue with the bug submission?
>         
>         
>                 -----Original Message-----
>                 From: Nick Berardi [mailto:nberardi@zigamorph.com] 
>                 Sent: 03 March 2004 14:55
>                 To: COOPER, Jonathan -Syntegra UK;
>                 mono-list@lists.ximian.com
>                 Subject: RE: [Mono-list] Simple code - differences in
>                 output between mono & .Net
>                 
>                 I was right here is your problem:
>                 
>                  
>                 
>                  
>                                 [MonoTODO("Implement on windows, for real")]
>                                 public static string[] GetLogicalDrives ()
>                                 { 
>                                         //FIXME: Hardcoded Paths
>                                         if ((int)Environment.OSVersion.Platform == 128)
>                                                 return new string[] { "/" };
>                                         else
>                                                 return new string [] { "A:\\", "C:\\" };
>                                 }
>                 
>                  
>                 
>                  
>                 
>                                            
>                 ______________________________________________________
>                 
>                 From: mono-list-admin@lists.ximian.com
>                 [mailto:mono-list-admin@lists.ximian.com] On Behalf Of
>                 jonathan.cooper@syntegra.com
>                 Sent: Wednesday, March 03, 2004 9:32 AM
>                 To: mono-list@lists.ximian.com
>                 Subject: [Mono-list] Simple code - differences in
>                 output between mono & .Net
>                 
>                 
>                  
>                 
>                 I have code (at the end of this message) in a .cs
>                 file, compiled with mcs and csc on Windows XP. When
>                 compiled with either compiler the executable works on
>                 both runtimes (.Net and mono). However, the output is
>                 different.
>                 
>                 Run under .Net:
>                 ------------------------
>                 Disk:  A:\
>                 Disk:  C:\
>                 Disk:  D:\
>                 Disk:  K:\
>                 Disk:  L:\
>                 Disk:  Q:\
>                 Disk:  T:\
>                 Disk:  U:\
>                 Disk:  X:\
>                 c:\
>                 Dir:  c:\Compaq
>                 Dir:  c:\Config.Msi
>                 Dir:  c:\Documents and Settings
>                 Dir:  c:\Program Files
>                 Dir:  c:\RECYCLER
>                 Dir:  c:\System Volume Information
>                 Dir:  c:\WINNT
>                 
>                  
>                 
>                 Basically the contents of the root c:\ drive
>                 
>                 Run under mono:
>                 --------------------------
>                 Disk:  A:\
>                 Disk:  C:\
>                 c:\
>                 >> a list of directories in the current directory
>                 rather than the root c:\ <<
>                 
>                 Is this due to an incomplete feature, or am I missing
>                 something?
>                 
>                 Thanks in advance,
>                 Jon Cooper
>                 
>                  
>                 
>                 ------------------------ CODE in drives.cs
>                 ------------------------
>                 
>                 using System;
>                 using System.IO;
>                 
>                 namespace test
>                 { 
>                    class test
>                    {
>                       [STAThread]
>                       static void Main(string[] args) 
>                       {
>                          string[] s = Directory.GetLogicalDrives();
>                          foreach(string drive in s)
>                             Console.WriteLine("Disk:  {0}",drive);
>                 
>                          string mydrive = Console.ReadLine();
>                 
>                          if(mydrive.Length != 0)
>                          {
>                            foreach(string d in
>                 Directory.GetDirectories(mydrive))
>                               Console.WriteLine("Dir:  {0}",d);
>                 
>                            Console.Read();  //pause
>                          }
>                       }
>                    }
>                 }
>                 
>                 
>                 
>                 ********************************************************************
>                 
>                 This email may contain information which is privileged
>                 or confidential. If you are not the intended recipient
>                 of this email, please notify the sender immediately
>                 and delete it without reading, copying, storing,
>                 forwarding or disclosing its contents to any other
>                 person
>                 Thank you
>                 
>                 Check us out at http://www.syntegra.com
>                 
>                 ********************************************************************
>                 
>         
>         
>         ********************************************************************
>         
>         This email may contain information which is privileged or
>         confidential. If you are not the intended recipient of this
>         email, please notify the sender immediately and delete it
>         without reading, copying, storing, forwarding or disclosing
>         its contents to any other person
>         Thank you
>         
>         Check us out at http://www.syntegra.com
>         
>         ********************************************************************
>         
>         
> 
> 
> ********************************************************************
> 
> This email may contain information which is privileged or
> confidential. If you are not the intended recipient of this email,
> please notify the sender immediately and delete it without reading,
> copying, storing, forwarding or disclosing its contents to any other
> person
> Thank you
> 
> Check us out at http://www.syntegra.com
> 
> ********************************************************************