- static StreamReader TryOpen (string name)
- {
- if (File.Exists (name))
- return new StreamReader (name, Encoding.ASCII);
- return null;
- }
-
- static DriveInfo [] LinuxGetDrives ()
- {
- using (StreamReader mounts = TryOpen ("/proc/mounts")){
- ArrayList drives = new ArrayList ();
- string line;
-
- while ((line = mounts.ReadLine ()) != null){
- if (line.StartsWith ("rootfs"))
- continue;
- int p;
-
- p = line.IndexOf (' ');
- if (p == -1)
- continue;
- string rest = line.Substring (p+1);
- p = rest.IndexOf (' ');
- if (p == -1)
- continue;
- string path = rest.Substring (0, p);
- rest = rest.Substring (p+1);
- p = rest.IndexOf (' ');
- if (p == -1)
- continue;
- string fstype = rest.Substring (0, p);
- drives.Add (new DriveInfo (_DriveType.Linux, path, fstype));
- }
-
- return (DriveInfo []) drives.ToArray (typeof (DriveInfo));
- }
- }
-
- static DriveInfo [] UnixGetDrives ()
- {
- DriveInfo [] di = null;
-
- try {
- using (StreamReader linux_ostype = TryOpen ("/proc/sys/kernel/ostype")){
- if (linux_ostype != null){
- string line = linux_ostype.ReadLine ();
- if (line == "Linux")
- di = LinuxGetDrives ();
- }
- }
-
- if (di != null)
- return di;
- } catch (Exception) {
- // If anything happens.
- }
-
- DriveInfo [] unknown = new DriveInfo [1];
- unknown [0]= new DriveInfo (_DriveType.GenericUnix, "/", "unixfs");
-
- return unknown;
- }
-
- static DriveInfo [] WindowsGetDrives ()
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO("Currently only implemented on Mono/Linux")]