Added DriveNotFoundException.cs. MonoIO.cs: Added ERROR_INVALID_DRIVE handling. Pass...
[mono.git] / mcs / class / corlib / System.IO / MonoIO.cs
index 81b60f744c8d5366408018aa6d14d6638b63c5aa..cc62d6957e64d98fd88f38ebcb7f042b1bd8c386 100644 (file)
@@ -1,4 +1,3 @@
-//
 // System.IO.MonoIO.cs: static interface to native filesystem.
 //
 // Author:
@@ -45,10 +44,7 @@ namespace System.IO
                public static readonly IntPtr
                        InvalidHandle = (IntPtr)(-1L);
 
-               public static readonly bool SupportsAsync = GetSupportsAsync ();
-
                // error methods
-
                public static Exception GetException (MonoIOError error)
                {
                        return GetException (String.Empty, error);
@@ -66,6 +62,9 @@ namespace System.IO
                                return new FileNotFoundException (message,
                                                                  path);
 
+                       case MonoIOError.ERROR_TOO_MANY_OPEN_FILES:
+                               return new IOException ("Too many open files", unchecked((int)0x80070000) | (int)error);
+                               
                        case MonoIOError.ERROR_PATH_NOT_FOUND:
                                message = String.Format ("Could not find a part of the path \"{0}\"", path);
                                return new DirectoryNotFoundException (message);
@@ -74,9 +73,19 @@ namespace System.IO
                                message = String.Format ("Access to the path \"{0}\" is denied.", path);
                                return new UnauthorizedAccessException (message);
 
+                       case MonoIOError.ERROR_INVALID_HANDLE:
+                               message = String.Format ("Invalid handle to path \"{0}\"", path);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
+                       case MonoIOError.ERROR_INVALID_DRIVE:
+                               message = String.Format ("Could not find the drive  '{0}'. The drive might not be ready or might not be mapped.", path);
+#if NET_2_0
+                               return new DriveNotFoundException (message);
+#else
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
+#endif
                        case MonoIOError.ERROR_FILE_EXISTS:
                                message = String.Format ("Could not create file \"{0}\". File already exists.", path);
-                               return new IOException (message);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
 
                        case MonoIOError.ERROR_FILENAME_EXCED_RANGE:
                                message = String.Format ("Path is too long. Path: {0}", path); 
@@ -84,15 +93,27 @@ namespace System.IO
 
                        case MonoIOError.ERROR_INVALID_PARAMETER:
                                message = String.Format ("Invalid parameter");
-                               return new IOException (message);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
+
+                       case MonoIOError.ERROR_WRITE_FAULT:
+                               message = String.Format ("Write fault on path {0}", path);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
 
                        case MonoIOError.ERROR_SHARING_VIOLATION:
                                message = String.Format ("Sharing violation on path {0}", path);
-                               return new IOException (message);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
+                               
+                       case MonoIOError.ERROR_LOCK_VIOLATION:
+                               message = String.Format ("Lock violation on path {0}", path);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
+
+                       case MonoIOError.ERROR_DIR_NOT_EMPTY:
+                               message = String.Format ("Directory {0} is not empty", path);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
                                
                        default:
                                message = String.Format ("Win32 IO returned {0}. Path: {1}", error, path);
-                               return new IOException (message);
+                               return new IOException (message, unchecked((int)0x80070000) | (int)error);
                        }
                }
 
@@ -105,14 +126,7 @@ namespace System.IO
                public extern static bool RemoveDirectory (string path, out MonoIOError error);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static IntPtr FindFirstFile (string path, out MonoIOStat stat, out MonoIOError error);
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static bool FindNextFile (IntPtr find, out MonoIOStat stat, out MonoIOError error);
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static bool FindClose (IntPtr find,
-                                                    out MonoIOError error);
+               public extern static string [] GetFileSystemEntries (string path, string pattern, int attrs, int mask, out MonoIOError error);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static string GetCurrentDirectory (out MonoIOError error);
@@ -144,10 +158,6 @@ namespace System.IO
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static MonoFileType GetFileType (IntPtr handle, out MonoIOError error);
 
-               // aio_* methods
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               extern static bool GetSupportsAsync ();
-
                public static bool Exists (string path, out MonoIOError error)
                {
                        FileAttributes attrs = GetFileAttributes (path,
@@ -374,20 +384,8 @@ namespace System.IO
                        get;
                }
 
-               public extern static char [] InvalidPathChars {
-                       [MethodImplAttribute (MethodImplOptions.InternalCall)]
-                       get;
-               }
-
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static int GetTempPath(out string path);
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static void BeginWrite (IntPtr handle,FileStreamAsyncResult ares);
-
-               [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static void BeginRead (IntPtr handle, FileStreamAsyncResult ares);
-
        }
 }