[reflection] Use coop handles for MonoMethod icalls (#4272)
[mono.git] / mono / io-layer / io.c
index 661067dc7b27b1461c9ee63858da5c519e0256f2..05d554a12c0c621abf4b44aabf6239d36781301b 100644 (file)
 #include <mono/io-layer/wapi.h>
 #include <mono/io-layer/wapi-private.h>
 #include <mono/io-layer/io-private.h>
-#include <mono/io-layer/timefuncs-private.h>
 #include <mono/io-layer/io-portability.h>
 #include <mono/io-layer/io-trace.h>
 #include <mono/utils/strenc.h>
 #include <mono/utils/mono-once.h>
 #include <mono/utils/mono-logger-internals.h>
-#include <mono/utils/w32handle.h>
+#include <mono/metadata/w32handle.h>
 
 /*
  * If SHM is disabled, this will point to a hash of _WapiFileShare structures, otherwise
 static GHashTable *file_share_hash;
 static mono_mutex_t file_share_mutex;
 
+static void
+time_t_to_filetime (time_t timeval, WapiFileTime *filetime)
+{
+       guint64 ticks;
+       
+       ticks = ((guint64)timeval * 10000000) + 116444736000000000ULL;
+       filetime->dwLowDateTime = ticks & 0xFFFFFFFF;
+       filetime->dwHighDateTime = ticks >> 32;
+}
+
 static void
 _wapi_handle_share_release (_WapiFileShare *share_info)
 {
@@ -1764,7 +1773,12 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
        if (attrs & FILE_FLAG_RANDOM_ACCESS)
                posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM);
 #endif
-       
+
+#ifdef F_RDAHEAD
+       if (attrs & FILE_FLAG_SEQUENTIAL_SCAN)
+               fcntl(fd, F_RDAHEAD, 1);
+#endif
+
 #ifndef S_ISFIFO
 #define S_ISFIFO(m) ((m & S_IFIFO) != 0)
 #endif
@@ -2913,7 +2927,6 @@ gboolean FindNextFile (gpointer handle, WapiFindData *find_data)
        gunichar2 *utf16_basename;
        time_t create_time;
        glong bytes;
-       int thr_ret;
        gboolean ret = FALSE;
        
        ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FIND,
@@ -2925,8 +2938,7 @@ gboolean FindNextFile (gpointer handle, WapiFindData *find_data)
                return(FALSE);
        }
 
-       thr_ret = mono_w32handle_lock_handle (handle);
-       g_assert (thr_ret == 0);
+       mono_w32handle_lock_handle (handle);
        
 retry:
        if (find_handle->count >= find_handle->num) {
@@ -2989,9 +3001,9 @@ retry:
        find_data->dwFileAttributes = _wapi_stat_to_file_attributes (utf8_filename, &buf, &linkbuf);
 #endif
 
-       _wapi_time_t_to_filetime (create_time, &find_data->ftCreationTime);
-       _wapi_time_t_to_filetime (buf.st_atime, &find_data->ftLastAccessTime);
-       _wapi_time_t_to_filetime (buf.st_mtime, &find_data->ftLastWriteTime);
+       time_t_to_filetime (create_time, &find_data->ftCreationTime);
+       time_t_to_filetime (buf.st_atime, &find_data->ftLastAccessTime);
+       time_t_to_filetime (buf.st_mtime, &find_data->ftLastWriteTime);
 
        if (find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                find_data->nFileSizeHigh = 0;
@@ -3032,8 +3044,7 @@ retry:
        g_free (utf16_basename);
 
 cleanup:
-       thr_ret = mono_w32handle_unlock_handle (handle);
-       g_assert (thr_ret == 0);
+       mono_w32handle_unlock_handle (handle);
        
        return(ret);
 }
@@ -3050,7 +3061,6 @@ gboolean FindClose (gpointer handle)
 {
        struct _WapiHandle_find *find_handle;
        gboolean ok;
-       int thr_ret;
 
        if (handle == NULL) {
                SetLastError (ERROR_INVALID_HANDLE);
@@ -3066,14 +3076,12 @@ gboolean FindClose (gpointer handle)
                return(FALSE);
        }
 
-       thr_ret = mono_w32handle_lock_handle (handle);
-       g_assert (thr_ret == 0);
+       mono_w32handle_lock_handle (handle);
        
        g_strfreev (find_handle->namelist);
        g_free (find_handle->dir_part);
 
-       thr_ret = mono_w32handle_unlock_handle (handle);
-       g_assert (thr_ret == 0);
+       mono_w32handle_unlock_handle (handle);
        
        mono_w32handle_unref (handle);
        
@@ -3302,9 +3310,9 @@ gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels lev
 
        g_free (utf8_name);
 
-       _wapi_time_t_to_filetime (create_time, &data->ftCreationTime);
-       _wapi_time_t_to_filetime (buf.st_atime, &data->ftLastAccessTime);
-       _wapi_time_t_to_filetime (buf.st_mtime, &data->ftLastWriteTime);
+       time_t_to_filetime (create_time, &data->ftCreationTime);
+       time_t_to_filetime (buf.st_atime, &data->ftLastAccessTime);
+       time_t_to_filetime (buf.st_mtime, &data->ftLastWriteTime);
 
        if (data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                data->nFileSizeHigh = 0;
@@ -3999,9 +4007,9 @@ GetLogicalDriveStrings_Mtab (guint32 len, gunichar2 *buf)
 #endif
 
 #if defined(HAVE_STATVFS) || defined(HAVE_STATFS)
-gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_bytes_avail,
-                           WapiULargeInteger *total_number_of_bytes,
-                           WapiULargeInteger *total_number_of_free_bytes)
+gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_bytes_avail,
+                           ULARGE_INTEGER *total_number_of_bytes,
+                           ULARGE_INTEGER *total_number_of_free_bytes)
 {
 #ifdef HAVE_STATVFS
        struct statvfs fsstat;
@@ -4082,9 +4090,9 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_
        return(TRUE);
 }
 #else
-gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_bytes_avail,
-                           WapiULargeInteger *total_number_of_bytes,
-                           WapiULargeInteger *total_number_of_free_bytes)
+gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_bytes_avail,
+                           ULARGE_INTEGER *total_number_of_bytes,
+                           ULARGE_INTEGER *total_number_of_free_bytes)
 {
        if (free_bytes_avail != NULL) {
                free_bytes_avail->QuadPart = (guint64) -1;