From f23f72c9de0cb7d03e5db68623440af9dcb19d6c Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Fri, 20 Jan 2017 11:32:48 -0500 Subject: [PATCH] [io-layer] Extract file (#4255) * [io-layer] Merge io related headers * [io-layer] Remove global variable _wapi_had_shut_down * [io-layer] Inline io-portability.c file into io.c * [io-layer] Inline locking.c file into io.c * [io-layer] Inline posix.c file into io.c * [file] Move metadata/file-io* files to metadata/w32file* * [io-layer] Extract file functions * [file] Remove overlapped parameter which is always NULL * [file] Remove SECURITY_ATTRIBUTES parameter which is always NULL * [file] Remove GET_FILEEX_INFO_LEVELS parameter which is always GetFileExInfoStandard * [file] Replace ULARGE_INTEGER parameter type with guint64 * [file] Replace WIN32_FILE_ATTRIBUTE_DATA parameter type with MonoIOStat * [file] Remove mono_w32file_create unused parameter tmplate * [file] Fix win32 build --- mcs/class/corlib/System.IO/FileOptions.cs | 2 +- mono/io-layer/Makefile.am | 15 - mono/io-layer/error.c | 18 - mono/io-layer/error.h | 1 - mono/io-layer/io-layer.h | 1 - mono/io-layer/io-portability.c | 581 ----- mono/io-layer/io-portability.h | 42 - mono/io-layer/io-private.h | 50 - mono/io-layer/io-trace.h | 20 - mono/io-layer/io.h | 249 -- mono/io-layer/locking.c | 205 -- mono/io-layer/posix.c | 115 - mono/io-layer/uglify.h | 68 - mono/io-layer/wapi-private.h | 54 - mono/io-layer/wapi-remap.h | 36 - mono/io-layer/wapi.c | 21 - mono/io-layer/wapi.h | 39 +- mono/metadata/Makefile.am | 15 +- mono/metadata/appdomain.c | 35 +- mono/metadata/console-null.c | 2 +- mono/metadata/domain.c | 8 +- mono/metadata/file-io-internals.h | 41 - mono/metadata/file-io-windows-internals.h | 15 - mono/metadata/file-io-windows.c | 43 - mono/metadata/file-mmap-posix.c | 2 +- mono/metadata/icall.c | 24 +- mono/metadata/sre-save.c | 17 +- mono/metadata/threads-types.h | 4 - mono/metadata/w32event-unix.c | 2 + mono/metadata/w32file-internals.h | 11 + .../w32file-unix-glob.c} | 74 +- .../w32file-unix-glob.h} | 37 +- .../io.c => metadata/w32file-unix.c} | 2144 ++++++++++------- mono/metadata/w32file-win32-internals.h | 15 + ...e-io-windows-uwp.c => w32file-win32-uwp.c} | 22 +- mono/metadata/w32file-win32.c | 358 +++ mono/metadata/{file-io.c => w32file.c} | 296 +-- mono/metadata/{file-io.h => w32file.h} | 228 +- mono/metadata/w32handle.c | 2 +- mono/metadata/w32mutex-unix.c | 2 + mono/metadata/w32process-unix.c | 43 +- mono/metadata/w32process.c | 1 + mono/metadata/w32semaphore-unix.c | 2 + mono/metadata/w32socket-internals.h | 20 +- mono/metadata/w32socket.c | 2 +- msvc/libmonoruntime.vcxproj | 10 +- msvc/libmonoruntime.vcxproj.filters | 10 +- msvc/pedump.vcxproj | 4 +- msvc/pedump.vcxproj.filters | 4 +- 49 files changed, 2219 insertions(+), 2791 deletions(-) delete mode 100644 mono/io-layer/io-portability.c delete mode 100644 mono/io-layer/io-portability.h delete mode 100644 mono/io-layer/io-private.h delete mode 100644 mono/io-layer/io-trace.h delete mode 100644 mono/io-layer/io.h delete mode 100644 mono/io-layer/locking.c delete mode 100644 mono/io-layer/posix.c delete mode 100644 mono/io-layer/uglify.h delete mode 100644 mono/io-layer/wapi-private.h delete mode 100644 mono/metadata/file-io-internals.h delete mode 100644 mono/metadata/file-io-windows-internals.h delete mode 100644 mono/metadata/file-io-windows.c create mode 100644 mono/metadata/w32file-internals.h rename mono/{io-layer/wapi_glob.c => metadata/w32file-unix-glob.c} (80%) rename mono/{io-layer/wapi_glob.h => metadata/w32file-unix-glob.h} (65%) rename mono/{io-layer/io.c => metadata/w32file-unix.c} (69%) create mode 100644 mono/metadata/w32file-win32-internals.h rename mono/metadata/{file-io-windows-uwp.c => w32file-win32-uwp.c} (81%) create mode 100644 mono/metadata/w32file-win32.c rename mono/metadata/{file-io.c => w32file.c} (75%) rename mono/metadata/{file-io.h => w32file.h} (54%) diff --git a/mcs/class/corlib/System.IO/FileOptions.cs b/mcs/class/corlib/System.IO/FileOptions.cs index 499319e343a..502974e7b00 100644 --- a/mcs/class/corlib/System.IO/FileOptions.cs +++ b/mcs/class/corlib/System.IO/FileOptions.cs @@ -50,7 +50,7 @@ namespace System.IO // The above is an internal value used by Path.GetTempFile to // get a file with 600 permissions, regardless of the umask // settings. If a value "1" must be introduced here, update - // both metadata/file-io.c and Path.GetTempFile + // both metadata/w32file.c and Path.GetTempFile // } } diff --git a/mono/io-layer/Makefile.am b/mono/io-layer/Makefile.am index 2247a51a71c..48e48baada2 100644 --- a/mono/io-layer/Makefile.am +++ b/mono/io-layer/Makefile.am @@ -12,30 +12,15 @@ libwapiincludedir = $(includedir)/mono-$(API_VER)/mono/io-layer OTHER_H = \ error.h \ - io.h \ - io-trace.h \ io-layer.h \ - io-portability.h \ - uglify.h \ wapi.h \ wapi-remap.h OTHER_SRC = \ error.c \ error.h \ - io.c \ - io.h \ - io-portability.c \ - io-portability.h \ - io-private.h \ io-layer.h \ - locking.c \ - posix.c \ - uglify.h \ - wapi_glob.h \ - wapi_glob.c \ wapi.h \ - wapi-private.h \ wapi.c diff --git a/mono/io-layer/error.c b/mono/io-layer/error.c index 5b1b22d6dcd..38a9141d2e1 100644 --- a/mono/io-layer/error.c +++ b/mono/io-layer/error.c @@ -14,7 +14,6 @@ #include #include "mono/io-layer/wapi.h" -#include "mono/io-layer/wapi-private.h" #include "mono/utils/mono-lazy-init.h" static pthread_key_t error_key; @@ -28,19 +27,6 @@ static void error_init(void) g_assert (ret == 0); } -static void error_cleanup (void) -{ - int ret; - - ret = pthread_key_delete (error_key); - g_assert (ret == 0); -} - -void _wapi_error_cleanup (void) -{ - mono_lazy_cleanup (&error_key_once, error_cleanup); -} - /** * GetLastError: * @@ -54,8 +40,6 @@ guint32 GetLastError(void) guint32 err; void *errptr; - if (_wapi_has_shut_down) - return 0; mono_lazy_initialize(&error_key_once, error_init); errptr=pthread_getspecific(error_key); err=GPOINTER_TO_UINT(errptr); @@ -73,8 +57,6 @@ void SetLastError(guint32 code) { int ret; - if (_wapi_has_shut_down) - return; /* Set the thread-local error code */ mono_lazy_initialize(&error_key_once, error_init); ret = pthread_setspecific(error_key, GUINT_TO_POINTER(code)); diff --git a/mono/io-layer/error.h b/mono/io-layer/error.h index d4ffe1e9235..9f6c640cc5e 100644 --- a/mono/io-layer/error.h +++ b/mono/io-layer/error.h @@ -82,7 +82,6 @@ G_BEGIN_DECLS guint32 GetLastError (void); void SetLastError (guint32 code); gint _wapi_get_win32_file_error (gint err); -void _wapi_error_cleanup (void); G_END_DECLS diff --git a/mono/io-layer/io-layer.h b/mono/io-layer/io-layer.h index e9096e25580..f1d2e05344e 100755 --- a/mono/io-layer/io-layer.h +++ b/mono/io-layer/io-layer.h @@ -47,7 +47,6 @@ typedef struct pollfd { #else /* EVERYONE ELSE */ #include "mono/io-layer/wapi.h" -#include "mono/io-layer/uglify.h" #endif /* HOST_WIN32 */ #ifdef __native_client__ diff --git a/mono/io-layer/io-portability.c b/mono/io-layer/io-portability.c deleted file mode 100644 index 282cbe93a29..00000000000 --- a/mono/io-layer/io-portability.c +++ /dev/null @@ -1,581 +0,0 @@ -/* - * io-portability.c: Optional filename mangling to try to cope with - * badly-written non-portable windows apps - * - * Author: - * Dick Porter (dick@ximian.com) - * - * Copyright (c) 2006 Novell, Inc. - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_DIRENT_H -# include -#endif -#include -#include - -#include -#include -#include -#include - -#undef DEBUG - -int _wapi_open (const char *pathname, int flags, mode_t mode) -{ - int fd; - gchar *located_filename; - - if (flags & O_CREAT) { - located_filename = mono_portability_find_file (pathname, FALSE); - if (located_filename == NULL) { - fd = open (pathname, flags, mode); - } else { - fd = open (located_filename, flags, mode); - g_free (located_filename); - } - } else { - fd = open (pathname, flags, mode); - if (fd == -1 && - (errno == ENOENT || errno == ENOTDIR) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - located_filename = mono_portability_find_file (pathname, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return (-1); - } - - fd = open (located_filename, flags, mode); - g_free (located_filename); - } - } - - - return(fd); -} - -int _wapi_access (const char *pathname, int mode) -{ - int ret; - - ret = access (pathname, mode); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (pathname, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = access (located_filename, mode); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_chmod (const char *pathname, mode_t mode) -{ - int ret; - - ret = chmod (pathname, mode); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (pathname, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = chmod (located_filename, mode); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_utime (const char *filename, const struct utimbuf *buf) -{ - int ret; - - ret = utime (filename, buf); - if (ret == -1 && - errno == ENOENT && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (filename, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = utime (located_filename, buf); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_unlink (const char *pathname) -{ - int ret; - - ret = unlink (pathname); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR || errno == EISDIR) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (pathname, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = unlink (located_filename); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_rename (const char *oldpath, const char *newpath) -{ - int ret; - gchar *located_newpath = mono_portability_find_file (newpath, FALSE); - - if (located_newpath == NULL) { - ret = rename (oldpath, newpath); - } else { - ret = rename (oldpath, located_newpath); - - if (ret == -1 && - (errno == EISDIR || errno == ENAMETOOLONG || - errno == ENOENT || errno == ENOTDIR || errno == EXDEV) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_oldpath = mono_portability_find_file (oldpath, TRUE); - - if (located_oldpath == NULL) { - g_free (located_oldpath); - g_free (located_newpath); - - errno = saved_errno; - return(-1); - } - - ret = rename (located_oldpath, located_newpath); - g_free (located_oldpath); - } - g_free (located_newpath); - } - - return(ret); -} - -int _wapi_stat (const char *path, struct stat *buf) -{ - int ret; - - ret = stat (path, buf); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (path, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = stat (located_filename, buf); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_lstat (const char *path, struct stat *buf) -{ - int ret; - - ret = lstat (path, buf); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (path, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = lstat (located_filename, buf); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_mkdir (const char *pathname, mode_t mode) -{ - int ret; - gchar *located_filename = mono_portability_find_file (pathname, FALSE); - - if (located_filename == NULL) { - ret = mkdir (pathname, mode); - } else { - ret = mkdir (located_filename, mode); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_rmdir (const char *pathname) -{ - int ret; - - ret = rmdir (pathname); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (pathname, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = rmdir (located_filename); - g_free (located_filename); - } - - return(ret); -} - -int _wapi_chdir (const char *path) -{ - int ret; - - ret = chdir (path); - if (ret == -1 && - (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) && - IS_PORTABILITY_SET) { - int saved_errno = errno; - gchar *located_filename = mono_portability_find_file (path, TRUE); - - if (located_filename == NULL) { - errno = saved_errno; - return(-1); - } - - ret = chdir (located_filename); - g_free (located_filename); - } - - return(ret); -} - -gchar *_wapi_basename (const gchar *filename) -{ - gchar *new_filename = g_strdup (filename), *ret; - - if (IS_PORTABILITY_SET) { - g_strdelimit (new_filename, "\\", '/'); - } - - if (IS_PORTABILITY_DRIVE && - g_ascii_isalpha (new_filename[0]) && - (new_filename[1] == ':')) { - int len = strlen (new_filename); - - g_memmove (new_filename, new_filename + 2, len - 2); - new_filename[len - 2] = '\0'; - } - - ret = g_path_get_basename (new_filename); - g_free (new_filename); - - return(ret); -} - -gchar *_wapi_dirname (const gchar *filename) -{ - gchar *new_filename = g_strdup (filename), *ret; - - if (IS_PORTABILITY_SET) { - g_strdelimit (new_filename, "\\", '/'); - } - - if (IS_PORTABILITY_DRIVE && - g_ascii_isalpha (new_filename[0]) && - (new_filename[1] == ':')) { - int len = strlen (new_filename); - - g_memmove (new_filename, new_filename + 2, len - 2); - new_filename[len - 2] = '\0'; - } - - ret = g_path_get_dirname (new_filename); - g_free (new_filename); - - return(ret); -} - -GDir *_wapi_g_dir_open (const gchar *path, guint flags, GError **error) -{ - GDir *ret; - - ret = g_dir_open (path, flags, error); - if (ret == NULL && - ((*error)->code == G_FILE_ERROR_NOENT || - (*error)->code == G_FILE_ERROR_NOTDIR || - (*error)->code == G_FILE_ERROR_NAMETOOLONG) && - IS_PORTABILITY_SET) { - gchar *located_filename = mono_portability_find_file (path, TRUE); - GError *tmp_error = NULL; - - if (located_filename == NULL) { - return(NULL); - } - - ret = g_dir_open (located_filename, flags, &tmp_error); - g_free (located_filename); - if (tmp_error == NULL) { - g_clear_error (error); - } - } - - return(ret); -} - - -static gint -file_compare (gconstpointer a, gconstpointer b) -{ - gchar *astr = *(gchar **) a; - gchar *bstr = *(gchar **) b; - - return strcmp (astr, bstr); -} - -static gint -get_errno_from_g_file_error (gint error) -{ - switch (error) { -#ifdef EACCESS - case G_FILE_ERROR_ACCES: - error = EACCES; - break; -#endif -#ifdef ENAMETOOLONG - case G_FILE_ERROR_NAMETOOLONG: - error = ENAMETOOLONG; - break; -#endif -#ifdef ENOENT - case G_FILE_ERROR_NOENT: - error = ENOENT; - break; -#endif -#ifdef ENOTDIR - case G_FILE_ERROR_NOTDIR: - error = ENOTDIR; - break; -#endif -#ifdef ENXIO - case G_FILE_ERROR_NXIO: - error = ENXIO; - break; -#endif -#ifdef ENODEV - case G_FILE_ERROR_NODEV: - error = ENODEV; - break; -#endif -#ifdef EROFS - case G_FILE_ERROR_ROFS: - error = EROFS; - break; -#endif -#ifdef ETXTBSY - case G_FILE_ERROR_TXTBSY: - error = ETXTBSY; - break; -#endif -#ifdef EFAULT - case G_FILE_ERROR_FAULT: - error = EFAULT; - break; -#endif -#ifdef ELOOP - case G_FILE_ERROR_LOOP: - error = ELOOP; - break; -#endif -#ifdef ENOSPC - case G_FILE_ERROR_NOSPC: - error = ENOSPC; - break; -#endif -#ifdef ENOMEM - case G_FILE_ERROR_NOMEM: - error = ENOMEM; - break; -#endif -#ifdef EMFILE - case G_FILE_ERROR_MFILE: - error = EMFILE; - break; -#endif -#ifdef ENFILE - case G_FILE_ERROR_NFILE: - error = ENFILE; - break; -#endif -#ifdef EBADF - case G_FILE_ERROR_BADF: - error = EBADF; - break; -#endif -#ifdef EINVAL - case G_FILE_ERROR_INVAL: - error = EINVAL; - break; -#endif -#ifdef EPIPE - case G_FILE_ERROR_PIPE: - error = EPIPE; - break; -#endif -#ifdef EAGAIN - case G_FILE_ERROR_AGAIN: - error = EAGAIN; - break; -#endif -#ifdef EINTR - case G_FILE_ERROR_INTR: - error = EINTR; - break; -#endif -#ifdef EWIO - case G_FILE_ERROR_IO: - error = EIO; - break; -#endif -#ifdef EPERM - case G_FILE_ERROR_PERM: - error = EPERM; - break; -#endif - case G_FILE_ERROR_FAILED: - error = ERROR_INVALID_PARAMETER; - break; - } - - return error; -} - -/* scandir using glib */ -gint _wapi_io_scandir (const gchar *dirname, const gchar *pattern, - gchar ***namelist) -{ - GError *error = NULL; - GDir *dir; - GPtrArray *names; - gint result; - wapi_glob_t glob_buf; - int flags = 0, i; - - dir = _wapi_g_dir_open (dirname, 0, &error); - if (dir == NULL) { - /* g_dir_open returns ENOENT on directories on which we don't - * have read/x permission */ - gint errnum = get_errno_from_g_file_error (error->code); - g_error_free (error); - if (errnum == ENOENT && - !_wapi_access (dirname, F_OK) && - _wapi_access (dirname, R_OK|X_OK)) { - errnum = EACCES; - } - - errno = errnum; - return -1; - } - - if (IS_PORTABILITY_CASE) { - flags = WAPI_GLOB_IGNORECASE; - } - - result = _wapi_glob (dir, pattern, flags, &glob_buf); - if (g_str_has_suffix (pattern, ".*")) { - /* Special-case the patterns ending in '.*', as - * windows also matches entries with no extension with - * this pattern. - * - * TODO: should this be a MONO_IOMAP option? - */ - gchar *pattern2 = g_strndup (pattern, strlen (pattern) - 2); - gint result2; - - g_dir_rewind (dir); - result2 = _wapi_glob (dir, pattern2, flags | WAPI_GLOB_APPEND | WAPI_GLOB_UNIQUE, &glob_buf); - - g_free (pattern2); - - if (result != 0) { - result = result2; - } - } - - g_dir_close (dir); - if (glob_buf.gl_pathc == 0) { - return(0); - } else if (result != 0) { - return(-1); - } - - names = g_ptr_array_new (); - for (i = 0; i < glob_buf.gl_pathc; i++) { - g_ptr_array_add (names, g_strdup (glob_buf.gl_pathv[i])); - } - - _wapi_globfree (&glob_buf); - - result = names->len; - if (result > 0) { - g_ptr_array_sort (names, file_compare); - g_ptr_array_set_size (names, result + 1); - - *namelist = (gchar **) g_ptr_array_free (names, FALSE); - } else { - g_ptr_array_free (names, TRUE); - } - - return result; -} diff --git a/mono/io-layer/io-portability.h b/mono/io-layer/io-portability.h deleted file mode 100644 index d7e9dba666d..00000000000 --- a/mono/io-layer/io-portability.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * io-portability.h: Optional filename mangling to try to cope with - * badly-written non-portable windows apps - * - * Author: - * Dick Porter (dick@ximian.com) - * - * Copyright (C) 2006 Novell, Inc. - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#ifndef _WAPI_IO_PORTABILITY_H_ -#define _WAPI_IO_PORTABILITY_H_ - -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -extern int _wapi_open (const char *pathname, int flags, mode_t mode); -extern int _wapi_access (const char *pathname, int mode); -extern int _wapi_chmod (const char *pathname, mode_t mode); -extern int _wapi_utime (const char *filename, const struct utimbuf *buf); -extern int _wapi_unlink (const char *pathname); -extern int _wapi_rename (const char *oldpath, const char *newpath); -extern int _wapi_stat (const char *path, struct stat *buf); -extern int _wapi_lstat (const char *path, struct stat *buf); -extern int _wapi_mkdir (const char *pathname, mode_t mode); -extern int _wapi_rmdir (const char *pathname); -extern int _wapi_chdir (const char *path); -extern gchar *_wapi_basename (const gchar *filename); -extern gchar *_wapi_dirname (const gchar *filename); -extern GDir *_wapi_g_dir_open (const gchar *path, guint flags, GError **error); -extern gint _wapi_io_scandir (const gchar *dirname, const gchar *pattern, - gchar ***namelist); - -G_END_DECLS - -#endif /* _WAPI_IO_PORTABILITY_H_ */ diff --git a/mono/io-layer/io-private.h b/mono/io-layer/io-private.h deleted file mode 100644 index 392b081ca79..00000000000 --- a/mono/io-layer/io-private.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * io-private.h: Private definitions for file, console and find handles - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - * Copyright 2011 Xamarin Inc - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#ifndef _WAPI_IO_PRIVATE_H_ -#define _WAPI_IO_PRIVATE_H_ - -#include -#include -#ifdef HAVE_DIRENT_H -#include -#endif - -#include -#include - -extern gboolean _wapi_lock_file_region (int fd, off_t offset, off_t length); -extern gboolean _wapi_unlock_file_region (int fd, off_t offset, off_t length); -extern gpointer _wapi_stdhandle_create (int fd, const gchar *name); - -/* Currently used for both FILE, CONSOLE and PIPE handle types. This may - * have to change in future. - */ -struct _WapiHandle_file -{ - gchar *filename; - struct _WapiFileShare *share_info; /* Pointer into shared mem */ - int fd; - guint32 security_attributes; - guint32 fileaccess; - guint32 sharemode; - guint32 attrs; -}; - -struct _WapiHandle_find -{ - gchar **namelist; - gchar *dir_part; - int num; - size_t count; -}; - -#endif /* _WAPI_IO_PRIVATE_H_ */ diff --git a/mono/io-layer/io-trace.h b/mono/io-layer/io-trace.h deleted file mode 100644 index e65fdc345a3..00000000000 --- a/mono/io-layer/io-trace.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * io-trace.h: tracing macros - * - * Authors: - * Marek Habersack - * - * Copyright 2016 Xamarin, Inc (http://xamarin.com/) - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#ifndef __IO_TRACE_H - -#ifdef DISABLE_IO_LAYER_TRACE -#define MONO_TRACE(...) -#else -#include "mono/utils/mono-logger-internals.h" -#define MONO_TRACE(...) mono_trace (__VA_ARGS__) -#endif - -#endif diff --git a/mono/io-layer/io.h b/mono/io-layer/io.h deleted file mode 100644 index 6e518b60e45..00000000000 --- a/mono/io-layer/io.h +++ /dev/null @@ -1,249 +0,0 @@ -/* - * io.h: File, console and find handles - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - */ - -#ifndef _WAPI_IO_H_ -#define _WAPI_IO_H_ - -#include - -#include "mono/io-layer/wapi.h" - -G_BEGIN_DECLS - -typedef struct _WapiSecurityAttributes WapiSecurityAttributes; - -struct _WapiSecurityAttributes -{ - guint32 nLength; - gpointer lpSecurityDescriptor; - gboolean bInheritHandle; -}; - -typedef struct _WapiOverlapped WapiOverlapped; - -struct _WapiOverlapped -{ - guint32 Internal; - guint32 InternalHigh; - guint32 Offset; - guint32 OffsetHigh; - gpointer hEvent; - gpointer handle1; - gpointer handle2; -}; - -typedef void (*WapiOverlappedCB) (guint32 error, guint32 numbytes, - WapiOverlapped *overlapped); - -#define GENERIC_READ 0x80000000 -#define GENERIC_WRITE 0x40000000 -#define GENERIC_EXECUTE 0x20000000 -#define GENERIC_ALL 0x10000000 - -#define FILE_SHARE_READ 0x00000001 -#define FILE_SHARE_WRITE 0x00000002 -#define FILE_SHARE_DELETE 0x00000004 - -#define CREATE_NEW 1 -#define CREATE_ALWAYS 2 -#define OPEN_EXISTING 3 -#define OPEN_ALWAYS 4 -#define TRUNCATE_EXISTING 5 - - -#define FILE_ATTRIBUTE_READONLY 0x00000001 -#define FILE_ATTRIBUTE_HIDDEN 0x00000002 -#define FILE_ATTRIBUTE_SYSTEM 0x00000004 -#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 -#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 -#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040 -#define FILE_ATTRIBUTE_NORMAL 0x00000080 -#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 -#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 -#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 -#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 -#define FILE_ATTRIBUTE_OFFLINE 0x00001000 -#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 -#define FILE_FLAG_OPEN_NO_RECALL 0x00100000 -#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000 -#define FILE_FLAG_POSIX_SEMANTICS 0x01000000 -#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000 -#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000 -#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 -#define FILE_FLAG_RANDOM_ACCESS 0x10000000 -#define FILE_FLAG_NO_BUFFERING 0x20000000 -#define FILE_FLAG_OVERLAPPED 0x40000000 -#define FILE_FLAG_WRITE_THROUGH 0x80000000 - -#define REPLACEFILE_WRITE_THROUGH 0x00000001 -#define REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002 - -#define MAX_PATH 260 - -typedef enum { - STD_INPUT_HANDLE=-10, - STD_OUTPUT_HANDLE=-11, - STD_ERROR_HANDLE=-12 -} WapiStdHandle; - -typedef enum { - FILE_BEGIN=0, - FILE_CURRENT=1, - FILE_END=2 -} WapiSeekMethod; - -typedef enum { - FILE_TYPE_UNKNOWN=0x0000, - FILE_TYPE_DISK=0x0001, - FILE_TYPE_CHAR=0x0002, - FILE_TYPE_PIPE=0x0003, - FILE_TYPE_REMOTE=0x8000 -} WapiFileType; - -typedef enum { - DRIVE_UNKNOWN=0, - DRIVE_NO_ROOT_DIR=1, - DRIVE_REMOVABLE=2, - DRIVE_FIXED=3, - DRIVE_REMOTE=4, - DRIVE_CDROM=5, - DRIVE_RAMDISK=6 -} WapiDriveType; - -typedef enum { - GetFileExInfoStandard=0x0000, - GetFileExMaxInfoLevel=0x0001 -} WapiGetFileExInfoLevels; - -typedef struct -{ - guint16 wYear; - guint16 wMonth; - guint16 wDayOfWeek; - guint16 wDay; - guint16 wHour; - guint16 wMinute; - guint16 wSecond; - guint16 wMilliseconds; -} WapiSystemTime; - -typedef struct { -#if G_BYTE_ORDER == G_BIG_ENDIAN - guint32 dwHighDateTime; - guint32 dwLowDateTime; -#else - guint32 dwLowDateTime; - guint32 dwHighDateTime; -#endif -} WapiFileTime; - -typedef struct -{ - guint32 dwFileAttributes; - WapiFileTime ftCreationTime; - WapiFileTime ftLastAccessTime; - WapiFileTime ftLastWriteTime; - guint32 nFileSizeHigh; - guint32 nFileSizeLow; - guint32 dwReserved0; - guint32 dwReserved1; - gunichar2 cFileName [MAX_PATH]; - gunichar2 cAlternateFileName [14]; -} WapiFindData; - -typedef struct -{ - guint32 dwFileAttributes; - WapiFileTime ftCreationTime; - WapiFileTime ftLastAccessTime; - WapiFileTime ftLastWriteTime; - guint32 nFileSizeHigh; - guint32 nFileSizeLow; -} WapiFileAttributesData; - -typedef union { - struct { - guint32 LowPart; - guint32 HighPart; - } u; - guint64 QuadPart; -} ULARGE_INTEGER; - -#define INVALID_SET_FILE_POINTER ((guint32)-1) -#define INVALID_FILE_SIZE ((guint32)0xFFFFFFFF) -#define INVALID_FILE_ATTRIBUTES ((guint32)-1) - -extern gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, - guint32 sharemode, - WapiSecurityAttributes *security, - guint32 createmode, - guint32 attrs, gpointer tmplate); -extern gboolean DeleteFile(const gunichar2 *name); -extern gpointer GetStdHandle(WapiStdHandle stdhandle); -extern gboolean ReadFile(gpointer handle, gpointer buffer, guint32 numbytes, - guint32 *bytesread, WapiOverlapped *overlapped); -extern gboolean WriteFile(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped); -extern gboolean FlushFileBuffers(gpointer handle); -extern gboolean SetEndOfFile(gpointer handle); -extern guint32 SetFilePointer(gpointer handle, gint32 movedistance, - gint32 *highmovedistance, guint32 method); -extern WapiFileType GetFileType(gpointer handle); -extern guint32 GetFileSize(gpointer handle, guint32 *highsize); -extern gboolean GetFileTime(gpointer handle, WapiFileTime *create_time, - WapiFileTime *last_access, - WapiFileTime *last_write); -extern gboolean SetFileTime(gpointer handle, const WapiFileTime *create_time, - const WapiFileTime *last_access, - const WapiFileTime *last_write); -extern gboolean FileTimeToSystemTime(const WapiFileTime *file_time, - WapiSystemTime *system_time); -extern gpointer FindFirstFile (const gunichar2 *pattern, - WapiFindData *find_data); -extern gboolean FindNextFile (gpointer handle, WapiFindData *find_data); -extern gboolean FindClose (gpointer handle); -extern gboolean CreateDirectory (const gunichar2 *name, - WapiSecurityAttributes *security); -extern gboolean RemoveDirectory (const gunichar2 *name); -extern gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name); -extern gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, - gboolean fail_if_exists); -extern gboolean ReplaceFile (const gunichar2 *replacedFileName, const gunichar2 *replacementFileName, - const gunichar2 *backupFileName, guint32 replaceFlags, - gpointer exclude, gpointer reserved); -extern guint32 GetFileAttributes (const gunichar2 *name); -extern gboolean GetFileAttributesEx (const gunichar2 *name, - WapiGetFileExInfoLevels level, - gpointer info); -extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs); -extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer); -extern gboolean SetCurrentDirectory (const gunichar2 *path); -extern gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe, - WapiSecurityAttributes *security, guint32 size); -extern gint32 GetLogicalDriveStrings (guint32 len, gunichar2 *buf); -extern gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_bytes_avail, - ULARGE_INTEGER *total_number_of_bytes, - ULARGE_INTEGER *total_number_of_free_bytes); -extern guint32 GetDriveType(const gunichar2 *root_path_name); -extern gboolean LockFile (gpointer handle, guint32 offset_low, - guint32 offset_high, guint32 length_low, - guint32 length_high); -extern gboolean UnlockFile (gpointer handle, guint32 offset_low, - guint32 offset_high, guint32 length_low, - guint32 length_high); -extern gboolean GetVolumeInformation (const gunichar2 *path, gunichar2 *volumename, int volumesize, int *outserial, int *maxcomp, int *fsflags, gunichar2 *fsbuffer, int fsbuffersize); - - -extern void _wapi_io_init (void); -extern void _wapi_io_cleanup (void); - -G_END_DECLS - -#endif /* _WAPI_IO_H_ */ diff --git a/mono/io-layer/locking.c b/mono/io-layer/locking.c deleted file mode 100644 index 86eb864365f..00000000000 --- a/mono/io-layer/locking.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * io.c: File, console and find handles - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - * Copyright (c) 2002-2009 Novell, Inc. - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -gboolean -_wapi_lock_file_region (int fd, off_t offset, off_t length) -{ -#if defined(__native_client__) - printf("WARNING: locking.c: _wapi_lock_file_region(): fcntl() not available on Native Client!\n"); - // behave as below -- locks are not available - return(TRUE); -#else - struct flock lock_data; - int ret; - - if (offset < 0 || length < 0) { - SetLastError (ERROR_INVALID_PARAMETER); - return(FALSE); - } - - lock_data.l_type = F_WRLCK; - lock_data.l_whence = SEEK_SET; - lock_data.l_start = offset; - lock_data.l_len = length; - - do { - ret = fcntl (fd, F_SETLK, &lock_data); - } while(ret == -1 && errno == EINTR); - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl returns %d", __func__, ret); - - if (ret == -1) { - /* - * if locks are not available (NFS for example), - * ignore the error - */ - if (errno == ENOLCK -#ifdef EOPNOTSUPP - || errno == EOPNOTSUPP -#endif -#ifdef ENOTSUP - || errno == ENOTSUP -#endif - ) { - return (TRUE); - } - - SetLastError (ERROR_LOCK_VIOLATION); - return(FALSE); - } - - return(TRUE); -#endif /* __native_client__ */ -} - -gboolean -_wapi_unlock_file_region (int fd, off_t offset, off_t length) -{ -#if defined(__native_client__) - printf("WARNING: locking.c: _wapi_unlock_file_region(): fcntl() not available on Native Client!\n"); - return (TRUE); -#else - struct flock lock_data; - int ret; - - lock_data.l_type = F_UNLCK; - lock_data.l_whence = SEEK_SET; - lock_data.l_start = offset; - lock_data.l_len = length; - - do { - ret = fcntl (fd, F_SETLK, &lock_data); - } while(ret == -1 && errno == EINTR); - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl returns %d", __func__, ret); - - if (ret == -1) { - /* - * if locks are not available (NFS for example), - * ignore the error - */ - if (errno == ENOLCK -#ifdef EOPNOTSUPP - || errno == EOPNOTSUPP -#endif -#ifdef ENOTSUP - || errno == ENOTSUP -#endif - ) { - return (TRUE); - } - - SetLastError (ERROR_LOCK_VIOLATION); - return(FALSE); - } - - return(TRUE); -#endif /* __native_client__ */ -} - -gboolean -LockFile (gpointer handle, guint32 offset_low, guint32 offset_high, - guint32 length_low, guint32 length_high) -{ - struct _WapiHandle_file *file_handle; - gboolean ok; - off_t offset, length; - int fd = GPOINTER_TO_UINT(handle); - - ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, - (gpointer *)&file_handle); - if (ok == FALSE) { - g_warning ("%s: error looking up file handle %p", __func__, - handle); - SetLastError (ERROR_INVALID_HANDLE); - return(FALSE); - } - - if (!(file_handle->fileaccess & GENERIC_READ) && - !(file_handle->fileaccess & GENERIC_WRITE) && - !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); - SetLastError (ERROR_ACCESS_DENIED); - return(FALSE); - } - -#ifdef HAVE_LARGE_FILE_SUPPORT - offset = ((gint64)offset_high << 32) | offset_low; - length = ((gint64)length_high << 32) | length_low; - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Locking handle %p, offset %lld, length %lld", __func__, handle, offset, length); -#else - if (offset_high > 0 || length_high > 0) { - SetLastError (ERROR_INVALID_PARAMETER); - return (FALSE); - } - offset = offset_low; - length = length_low; - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Locking handle %p, offset %ld, length %ld", __func__, - handle, offset, length); -#endif - - return(_wapi_lock_file_region (fd, offset, length)); -} - -gboolean -UnlockFile (gpointer handle, guint32 offset_low, - guint32 offset_high, guint32 length_low, - guint32 length_high) -{ - struct _WapiHandle_file *file_handle; - gboolean ok; - off_t offset, length; - int fd = GPOINTER_TO_UINT(handle); - - ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, - (gpointer *)&file_handle); - if (ok == FALSE) { - g_warning ("%s: error looking up file handle %p", __func__, - handle); - SetLastError (ERROR_INVALID_HANDLE); - return(FALSE); - } - - if (!(file_handle->fileaccess & GENERIC_READ) && - !(file_handle->fileaccess & GENERIC_WRITE) && - !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); - SetLastError (ERROR_ACCESS_DENIED); - return(FALSE); - } - -#ifdef HAVE_LARGE_FILE_SUPPORT - offset = ((gint64)offset_high << 32) | offset_low; - length = ((gint64)length_high << 32) | length_low; - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unlocking handle %p, offset %lld, length %lld", __func__, handle, offset, length); -#else - offset = offset_low; - length = length_low; - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unlocking handle %p, offset %ld, length %ld", __func__, handle, offset, length); -#endif - - return(_wapi_unlock_file_region (fd, offset, length)); -} diff --git a/mono/io-layer/posix.c b/mono/io-layer/posix.c deleted file mode 100644 index 995795bb326..00000000000 --- a/mono/io-layer/posix.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * posix.c: Posix-specific support. - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - * Copyright (c) 2002-2009 Novell, Inc. - * Copyright 2011 Xamarin Inc - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static guint32 -convert_from_flags(int flags) -{ - guint32 fileaccess=0; - -#ifndef O_ACCMODE -#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) -#endif - - if((flags & O_ACCMODE) == O_RDONLY) { - fileaccess=GENERIC_READ; - } else if ((flags & O_ACCMODE) == O_WRONLY) { - fileaccess=GENERIC_WRITE; - } else if ((flags & O_ACCMODE) == O_RDWR) { - fileaccess=GENERIC_READ|GENERIC_WRITE; - } else { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't figure out flags 0x%x", __func__, flags); - } - - /* Maybe sort out create mode too */ - - return(fileaccess); -} - - -gpointer _wapi_stdhandle_create (int fd, const gchar *name) -{ - struct _WapiHandle_file file_handle = {0}; - gpointer handle; - int flags; - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating standard handle type %s, fd %d", __func__, - name, fd); - -#if !defined(__native_client__) - /* Check if fd is valid */ - do { - flags=fcntl(fd, F_GETFL); - } while (flags == -1 && errno == EINTR); - - if(flags==-1) { - /* Invalid fd. Not really much point checking for EBADF - * specifically - */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl error on fd %d: %s", __func__, fd, - strerror(errno)); - - SetLastError (_wapi_get_win32_file_error (errno)); - return(INVALID_HANDLE_VALUE); - } - file_handle.fileaccess=convert_from_flags(flags); -#else - /* - * fcntl will return -1 in nacl, as there is no real file system API. - * Yet, standard streams are available. - */ - file_handle.fileaccess = (fd == STDIN_FILENO) ? GENERIC_READ : GENERIC_WRITE; -#endif - - file_handle.fd = fd; - file_handle.filename = g_strdup(name); - /* some default security attributes might be needed */ - file_handle.security_attributes=0; - - /* Apparently input handles can't be written to. (I don't - * know if output or error handles can't be read from.) - */ - if (fd == 0) { - file_handle.fileaccess &= ~GENERIC_WRITE; - } - - file_handle.sharemode=0; - file_handle.attrs=0; - - handle = mono_w32handle_new_fd (MONO_W32HANDLE_CONSOLE, fd, &file_handle); - if (handle == INVALID_HANDLE_VALUE) { - g_warning ("%s: error creating file handle", __func__); - SetLastError (ERROR_GEN_FAILURE); - return(INVALID_HANDLE_VALUE); - } - - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning handle %p", __func__, handle); - - return(handle); -} - diff --git a/mono/io-layer/uglify.h b/mono/io-layer/uglify.h deleted file mode 100644 index 0335d0a7200..00000000000 --- a/mono/io-layer/uglify.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * uglify.h: Optional header to provide the nasty w32 typedefs - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - */ - -#ifndef _WAPI_UGLIFY_H_ -#define _WAPI_UGLIFY_H_ - -/* Include this file if you insist on using the nasty Win32 typedefs */ - -#include - -#include "mono/io-layer/wapi.h" - -typedef const gunichar2 *LPCTSTR; -typedef gunichar2 *LPTSTR; -typedef const char *LPCSTR; -typedef char *LPSTR; -typedef guint8 BYTE; -typedef guint8 *LPBYTE; -typedef guint16 WORD; -typedef guint32 DWORD; -typedef gpointer PVOID; -typedef gpointer LPVOID; -typedef gboolean BOOL; -typedef guint32 *LPDWORD; -typedef gint32 LONG; -typedef guint32 ULONG; -typedef gint32 *PLONG; -typedef guint64 LONGLONG; -typedef gunichar2 TCHAR; -typedef size_t SIZE_T; -typedef guint64 ULONG64; -typedef guint UINT; -typedef gconstpointer LPCVOID; - -typedef gpointer HANDLE; -typedef gpointer *LPHANDLE; -typedef gpointer HMODULE; -typedef gpointer HINSTANCE; -typedef gpointer HWND; -typedef gpointer HKEY; - -typedef WapiSecurityAttributes SECURITY_ATTRIBUTES; -typedef WapiSecurityAttributes *LPSECURITY_ATTRIBUTES; -typedef WapiOverlapped *LPOVERLAPPED; -typedef WapiOverlappedCB LPOVERLAPPED_COMPLETION_ROUTINE; -typedef WapiFileTime FILETIME; -typedef WapiFileTime *LPFILETIME; -typedef WapiSystemTime SYSTEMTIME; -typedef WapiSystemTime *LPSYSTEMTIME; -typedef WapiFindData WIN32_FIND_DATA; -typedef WapiFindData *LPWIN32_FIND_DATA; -typedef WapiFileAttributesData WIN32_FILE_ATTRIBUTE_DATA; -typedef WapiGetFileExInfoLevels GET_FILEEX_INFO_LEVELS; - -#define CONST const -#define VOID void - -#define IN -#define OUT -#define WINAPI - -#endif /* _WAPI_UGLIFY_H_ */ diff --git a/mono/io-layer/wapi-private.h b/mono/io-layer/wapi-private.h deleted file mode 100644 index f39d4e4fab4..00000000000 --- a/mono/io-layer/wapi-private.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * wapi-private.h: internal definitions of handles and shared memory layout - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002-2006 Novell, Inc. - */ - -#ifndef _WAPI_PRIVATE_H_ -#define _WAPI_PRIVATE_H_ - -#include -#include -#include - -#include -#include - -#include - -/* There doesn't seem to be a defined symbol for this */ -#define _WAPI_THREAD_CURRENT (gpointer)0xFFFFFFFE - -extern gboolean _wapi_has_shut_down; - -#include -#include - -struct _WapiHandle_shared_ref -{ - /* This will be split 16:16 with the shared file segment in - * the top half, when I implement space increases - */ - guint32 offset; -}; - -struct _WapiFileShare -{ -#ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA - WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA -#endif - guint64 device; - guint64 inode; - pid_t opened_by_pid; - guint32 sharemode; - guint32 access; - guint32 handle_refs; - guint32 timestamp; -}; - -typedef struct _WapiFileShare _WapiFileShare; - -#endif /* _WAPI_PRIVATE_H_ */ diff --git a/mono/io-layer/wapi-remap.h b/mono/io-layer/wapi-remap.h index 7cc3b89ff38..80034f50be7 100644 --- a/mono/io-layer/wapi-remap.h +++ b/mono/io-layer/wapi-remap.h @@ -15,41 +15,5 @@ #define GetLastError wapi_GetLastError #define SetLastError wapi_SetLastError #define CloseHandle wapi_CloseHandle -#define CreateFile wapi_CreateFile -#define DeleteFile wapi_DeleteFile -#define GetStdHandle wapi_GetStdHandle -#define ReadFile wapi_ReadFile -#define WriteFile wapi_WriteFile -#define FlushFileBuffers wapi_FlushFileBuffers -#define SetEndOfFile wapi_SetEndOfFile -#define SetFilePointer wapi_SetFilePointer -#define GetFileType wapi_GetFileType -#define GetFileSize wapi_GetFileSize -#define GetFileTime wapi_GetFileTime -#define SetFileTime wapi_SetFileTime -#define FileTimeToSystemTime wapi_FileTimeToSystemTime -#define FindFirstFile wapi_FindFirstFile -#define FindNextFile wapi_FindNextFile -#define FindClose wapi_FindClose -#define CreateDirectory wapi_CreateDirectory -#define RemoveDirectory wapi_RemoveDirectory -#define MoveFile wapi_MoveFile -#define CopyFile wapi_CopyFile -#define ReplaceFile wapi_ReplaceFile -#define GetFileAttributes wapi_GetFileAttributes -#define GetFileAttributesEx wapi_GetFileAttributesEx -#define SetFileAttributes wapi_SetFileAttributes -#define GetCurrentDirectory wapi_GetCurrentDirectory -#define SetCurrentDirectory wapi_SetCurrentDirectory -#define CreatePipe wapi_CreatePipe -#define GetLogicalDriveStrings wapi_GetLogicalDriveStrings -#define GetDiskFreeSpaceEx wapi_GetDiskFreeSpaceEx -#define GetDriveType wapi_GetDriveType -#define LockFile wapi_LockFile -#define UnlockFile wapi_UnlockFile -#define GetVolumeInformation wapi_GetVolumeInformation -#define ImpersonateLoggedOnUser wapi_ImpersonateLoggedOnUser -#define RevertToSelf wapi_RevertToSelf -#define GetSystemInfo wapi_GetSystemInfo #endif /* __WAPI_REMAP_H__ */ diff --git a/mono/io-layer/wapi.c b/mono/io-layer/wapi.c index d4da229603e..14dc672e8ee 100644 --- a/mono/io-layer/wapi.c +++ b/mono/io-layer/wapi.c @@ -1,30 +1,9 @@ #include "wapi.h" -#include "io-trace.h" -#include "io.h" - #include "mono/utils/mono-lazy-init.h" #include "mono/metadata/w32handle.h" -gboolean _wapi_has_shut_down = FALSE; - -void -wapi_init (void) -{ - _wapi_io_init (); -} - -void -wapi_cleanup (void) -{ - g_assert (_wapi_has_shut_down == FALSE); - _wapi_has_shut_down = TRUE; - - _wapi_error_cleanup (); - _wapi_io_cleanup (); -} - /* Use this instead of getpid(), to cope with linuxthreads. It's a * function rather than a variable lookup because we need to get at * this before share_init() might have been called. */ diff --git a/mono/io-layer/wapi.h b/mono/io-layer/wapi.h index fb0bf4fbce9..4409210db2d 100644 --- a/mono/io-layer/wapi.h +++ b/mono/io-layer/wapi.h @@ -10,28 +10,45 @@ #ifndef _WAPI_WAPI_H_ #define _WAPI_WAPI_H_ +#include #include +#ifdef HAVE_DIRENT_H +#include +#endif +#include +#include #include +#include #include -#include -#include #include +#include G_BEGIN_DECLS -#define WAIT_FAILED ((int) 0xFFFFFFFF) -#define WAIT_OBJECT_0 ((int) 0x00000000) -#define WAIT_ABANDONED_0 ((int) 0x00000080) -#define WAIT_TIMEOUT ((int) 0x00000102) -#define WAIT_IO_COMPLETION ((int) 0x000000C0) +#define WAIT_FAILED ((gint) 0xFFFFFFFF) +#define WAIT_OBJECT_0 ((gint) 0x00000000) +#define WAIT_ABANDONED_0 ((gint) 0x00000080) +#define WAIT_TIMEOUT ((gint) 0x00000102) +#define WAIT_IO_COMPLETION ((gint) 0x000000C0) -void -wapi_init (void); +#ifdef DISABLE_IO_LAYER_TRACE +#define MONO_TRACE(...) +#else +#define MONO_TRACE(...) mono_trace (__VA_ARGS__) +#endif -void -wapi_cleanup (void); +#define WINAPI + +typedef guint32 DWORD; +typedef gboolean BOOL; +typedef gint32 LONG; +typedef guint32 ULONG; +typedef guint UINT; + +typedef gpointer HANDLE; +typedef gpointer HMODULE; gboolean CloseHandle (gpointer handle); diff --git a/mono/metadata/Makefile.am b/mono/metadata/Makefile.am index 5deda477e2d..4a997d3fc4c 100644 --- a/mono/metadata/Makefile.am +++ b/mono/metadata/Makefile.am @@ -3,8 +3,8 @@ win32_sources = \ console-win32.c \ console-win32-internals.h \ cominterop-win32-internals.h \ - file-io-windows.c \ - file-io-windows-internals.h \ + w32file-win32.c \ + w32file-win32-internals.h \ icall-windows.c \ icall-windows-internals.h \ marshal-windows.c \ @@ -49,7 +49,10 @@ unix_sources = \ w32process-unix-bsd.c \ w32process-unix-haiku.c \ w32process-unix-default.c \ - w32socket-unix.c + w32socket-unix.c \ + w32file-unix.c \ + w32file-unix-glob.c \ + w32file-unix-glob.h platform_sources = $(unix_sources) endif @@ -151,9 +154,9 @@ common_sources = \ exception.c \ exception.h \ exception-internals.h \ - file-io.c \ - file-io.h \ - file-io-internals.h \ + w32file.c \ + w32file.h \ + w32file-internals.h \ filewatcher.c \ filewatcher.h \ gc-internals.h \ diff --git a/mono/metadata/appdomain.c b/mono/metadata/appdomain.c index 74323ab37b3..a2c8c353fd3 100644 --- a/mono/metadata/appdomain.c +++ b/mono/metadata/appdomain.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include #include @@ -1398,6 +1398,7 @@ shadow_copy_sibling (gchar *src, gint srclen, const char *extension, gchar *targ { guint16 *orig, *dest; gboolean copy_result; + gint32 copy_error; strcpy (src + srclen - tail_len, extension); @@ -1417,18 +1418,14 @@ shadow_copy_sibling (gchar *src, gint srclen, const char *extension, gchar *targ strcpy (target + targetlen - tail_len, extension); dest = g_utf8_to_utf16 (target, strlen (target), NULL, NULL, NULL); - DeleteFile (dest); + mono_w32file_delete (dest); -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) - copy_result = CopyFile (orig, dest, FALSE); -#else - copy_result = SUCCEEDED (CopyFile2 (orig, dest, NULL)); -#endif + copy_result = mono_w32file_copy (orig, dest, TRUE, ©_error); /* Fix for bug #556884 - make sure the files have the correct mode so that they can be * overwritten when updated in their original locations. */ if (copy_result) - copy_result = SetFileAttributes (dest, FILE_ATTRIBUTE_NORMAL); + copy_result = mono_w32file_set_attributes (dest, FILE_ATTRIBUTE_NORMAL); g_free (orig); g_free (dest); @@ -1592,15 +1589,14 @@ shadow_copy_create_ini (const char *shadow, const char *filename) if (!u16_ini) { return FALSE; } - handle = (void **)CreateFile (u16_ini, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, CREATE_NEW, FileAttributes_Normal, NULL); + handle = (void **)mono_w32file_create (u16_ini, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, CREATE_NEW, FileAttributes_Normal); g_free (u16_ini); if (handle == INVALID_HANDLE_VALUE) { return FALSE; } full_path = mono_path_resolve_symlinks (filename); - result = WriteFile (handle, full_path, strlen (full_path), &n, NULL); + result = mono_w32file_write (handle, full_path, strlen (full_path), &n); g_free (full_path); CloseHandle (handle); return result; @@ -1695,6 +1691,7 @@ mono_make_shadow_copy (const char *filename, MonoError *oerror) char *dir_name = g_path_get_dirname (filename); MonoDomain *domain = mono_domain_get (); char *shadow_dir; + gint32 copy_error; mono_error_init (oerror); @@ -1740,27 +1737,23 @@ mono_make_shadow_copy (const char *filename, MonoError *oerror) orig = g_utf8_to_utf16 (filename, strlen (filename), NULL, NULL, NULL); dest = g_utf8_to_utf16 (shadow, strlen (shadow), NULL, NULL, NULL); - DeleteFile (dest); + mono_w32file_delete (dest); /* Fix for bug #17066 - make sure we can read the file. if not then don't error but rather * let the assembly fail to load. This ensures you can do Type.GetType("NS.T, NonExistantAssembly) * and not have it runtime error" */ - attrs = GetFileAttributes (orig); + attrs = mono_w32file_get_attributes (orig); if (attrs == INVALID_FILE_ATTRIBUTES) { g_free (shadow); return (char *)filename; } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) - copy_result = CopyFile (orig, dest, FALSE); -#else - copy_result = SUCCEEDED (CopyFile2 (orig, dest, NULL)); -#endif + copy_result = mono_w32file_copy (orig, dest, TRUE, ©_error); /* Fix for bug #556884 - make sure the files have the correct mode so that they can be * overwritten when updated in their original locations. */ if (copy_result) - copy_result = SetFileAttributes (dest, FILE_ATTRIBUTE_NORMAL); + copy_result = mono_w32file_set_attributes (dest, FILE_ATTRIBUTE_NORMAL); g_free (dest); g_free (orig); @@ -1772,7 +1765,7 @@ mono_make_shadow_copy (const char *filename, MonoError *oerror) if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND) return NULL; /* file not found, shadow copy failed */ - mono_error_set_execution_engine (oerror, "Failed to create shadow copy (CopyFile)."); + mono_error_set_execution_engine (oerror, "Failed to create shadow copy (mono_w32file_copy)."); return NULL; } @@ -1791,7 +1784,7 @@ mono_make_shadow_copy (const char *filename, MonoError *oerror) if (!copy_result) { g_free (shadow); - mono_error_set_execution_engine (oerror, "Failed to create shadow copy of sibling data (CopyFile)."); + mono_error_set_execution_engine (oerror, "Failed to create shadow copy of sibling data (mono_w32file_copy)."); return NULL; } diff --git a/mono/metadata/console-null.c b/mono/metadata/console-null.c index b8367e888f7..233e2aef04e 100644 --- a/mono/metadata/console-null.c +++ b/mono/metadata/console-null.c @@ -30,7 +30,7 @@ mono_console_handle_async_ops (void) MonoBoolean ves_icall_System_ConsoleDriver_Isatty (HANDLE handle) { - return (GetFileType (handle) == FILE_TYPE_CHAR); + return mono_w32file_get_type (handle) == FILE_TYPE_CHAR; } MonoBoolean diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c index 76cfe9979db..908f572a5ff 100644 --- a/mono/metadata/domain.c +++ b/mono/metadata/domain.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -484,13 +485,13 @@ mono_init_internal (const char *filename, const char *exe_filename, const char * #ifndef HOST_WIN32 mono_w32handle_init (); mono_w32handle_namespace_init (); - wapi_init (); #endif mono_w32mutex_init (); mono_w32semaphore_init (); mono_w32event_init (); mono_w32process_init (); + mono_w32file_init (); #ifndef DISABLE_PERFCOUNTERS mono_perfcounters_init (); @@ -852,10 +853,7 @@ mono_cleanup (void) mono_coop_mutex_destroy (&appdomains_mutex); mono_w32process_cleanup (); - -#ifndef HOST_WIN32 - wapi_cleanup (); -#endif + mono_w32file_cleanup (); } void diff --git a/mono/metadata/file-io-internals.h b/mono/metadata/file-io-internals.h deleted file mode 100644 index ad455297d11..00000000000 --- a/mono/metadata/file-io-internals.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Microsoft - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ -#ifndef __MONO_FILE_IO_INTERNALS_H__ -#define __MONO_FILE_IO_INTERNALS_H__ - -#include -#include -#include "mono/metadata/object.h" -#include "mono/metadata/object-internals.h" - -gboolean -mono_file_io_move_file (gunichar2 *path, gunichar2 *dest, gint32 *error); - -gboolean -mono_file_io_copy_file (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error); - -gint64 -mono_file_io_get_file_size (HANDLE handle, gint32 *error); - -gboolean -mono_file_io_lock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error); - -gboolean -mono_file_io_replace_file (gunichar2 *destinationFileName, gunichar2 *sourceFileName, - gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error); - -gboolean -mono_file_io_unlock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error); - -HANDLE -mono_file_io_get_console_output (void); - -HANDLE -mono_file_io_get_console_error (void); - -HANDLE -mono_file_io_get_console_input (void); - -#endif /* __MONO_FILE_IO_INTERNALS_H__ */ diff --git a/mono/metadata/file-io-windows-internals.h b/mono/metadata/file-io-windows-internals.h deleted file mode 100644 index df372e8e747..00000000000 --- a/mono/metadata/file-io-windows-internals.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2016 Microsoft - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ -#ifndef _MONO_METADATA_FILEIO_WINDOWS_H_ -#define _MONO_METADATA_FILEIO_WINDOWS_H_ - -#include -#include - -#ifdef HOST_WIN32 -#include "mono/metadata/file-io.h" -#include "mono/metadata/file-io-internals.h" -#endif /* HOST_WIN32 */ -#endif /* _MONO_METADATA_FILEIO_WINDOWS_H_ */ diff --git a/mono/metadata/file-io-windows.c b/mono/metadata/file-io-windows.c deleted file mode 100644 index e7dd11167ce..00000000000 --- a/mono/metadata/file-io-windows.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * file-io-windows.c: Windows File IO internal calls. - * - * Copyright 2016 Microsoft - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ -#include -#include - -#if defined(HOST_WIN32) -#include -#include -#include "mono/metadata/file-io-windows-internals.h" - -gunichar2 -ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar () -{ - return (gunichar2) ':'; /* colon */ -} - -gunichar2 -ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar () -{ - return (gunichar2) '\\'; /* backslash */ -} - -gunichar2 -ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar () -{ - return (gunichar2) '/'; /* forward slash */ -} - -gunichar2 -ves_icall_System_IO_MonoIO_get_PathSeparator () -{ - return (gunichar2) ';'; /* semicolon */ -} - -void ves_icall_System_IO_MonoIO_DumpHandles (void) -{ - return; -} -#endif /* HOST_WIN32 */ diff --git a/mono/metadata/file-mmap-posix.c b/mono/metadata/file-mmap-posix.c index 4b9ce74499e..64332ed18d1 100644 --- a/mono/metadata/file-mmap-posix.c +++ b/mono/metadata/file-mmap-posix.c @@ -32,7 +32,7 @@ #include -#include +#include #include #include #include diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index b798a6e7c29..f0dc4ef1238 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include @@ -6691,7 +6691,7 @@ mono_icall_get_logical_drives (void) ptr = buf; while (size > initial_size) { - size = (guint) GetLogicalDriveStrings (initial_size, ptr); + size = (guint) mono_w32file_get_logical_drive (initial_size, ptr); if (size > initial_size) { if (ptr != buf) g_free (ptr); @@ -6747,7 +6747,7 @@ ves_icall_System_IO_DriveInfo_GetDriveFormat (MonoString *path) MonoError error; gunichar2 volume_name [MAX_PATH + 1]; - if (GetVolumeInformation (mono_string_chars (path), NULL, 0, NULL, NULL, NULL, volume_name, MAX_PATH + 1) == FALSE) + if (mono_w32file_get_volume_information (mono_string_chars (path), NULL, 0, NULL, NULL, NULL, volume_name, MAX_PATH + 1) == FALSE) return NULL; MonoString *result = mono_string_from_utf16_checked (volume_name, &error); mono_error_set_pending_exception (&error); @@ -7026,24 +7026,12 @@ ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (MonoString *path_name, guint64 * gint32 *error) { gboolean result; - ULARGE_INTEGER wapi_free_bytes_avail; - ULARGE_INTEGER wapi_total_number_of_bytes; - ULARGE_INTEGER wapi_total_number_of_free_bytes; *error = ERROR_SUCCESS; - result = GetDiskFreeSpaceEx (mono_string_chars (path_name), &wapi_free_bytes_avail, &wapi_total_number_of_bytes, - &wapi_total_number_of_free_bytes); - if (result) { - *free_bytes_avail = wapi_free_bytes_avail.QuadPart; - *total_number_of_bytes = wapi_total_number_of_bytes.QuadPart; - *total_number_of_free_bytes = wapi_total_number_of_free_bytes.QuadPart; - } else { - *free_bytes_avail = 0; - *total_number_of_bytes = 0; - *total_number_of_free_bytes = 0; + result = mono_w32file_get_disk_free_space (mono_string_chars (path_name), free_bytes_avail, total_number_of_bytes, total_number_of_free_bytes); + if (!result) *error = GetLastError (); - } return result; } @@ -7052,7 +7040,7 @@ ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (MonoString *path_name, guint64 * static inline guint32 mono_icall_drive_info_get_drive_type (MonoString *root_path_name) { - return GetDriveType (mono_string_chars (root_path_name)); + return mono_w32file_get_drive_type (mono_string_chars (root_path_name)); } #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ diff --git a/mono/metadata/sre-save.c b/mono/metadata/sre-save.c index 421216d8113..4d94b5524b9 100644 --- a/mono/metadata/sre-save.c +++ b/mono/metadata/sre-save.c @@ -24,6 +24,7 @@ #include "mono/metadata/security-manager.h" #include "mono/metadata/tabledefs.h" #include "mono/metadata/tokentype.h" +#include "mono/metadata/w32file.h" #include "mono/utils/checked-build.h" #include "mono/utils/mono-digest.h" @@ -2737,8 +2738,8 @@ static void checked_write_file (HANDLE f, gconstpointer buffer, guint32 numbytes) { guint32 dummy; - if (!WriteFile (f, buffer, numbytes, &dummy, NULL)) - g_error ("WriteFile returned %d\n", GetLastError ()); + if (!mono_w32file_write (f, buffer, numbytes, &dummy)) + g_error ("mono_w32file_write returned %d\n", GetLastError ()); } /* @@ -3032,8 +3033,8 @@ mono_image_create_pefile (MonoReflectionModuleBuilder *mb, HANDLE file, MonoErro if (!assembly->sections [i].size) continue; - if (SetFilePointer (file, assembly->sections [i].offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - g_error ("SetFilePointer returned %d\n", GetLastError ()); + if (mono_w32file_seek (file, assembly->sections [i].offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + g_error ("mono_w32file_seek returned %d\n", GetLastError ()); switch (i) { case MONO_SECTION_TEXT: @@ -3092,10 +3093,10 @@ mono_image_create_pefile (MonoReflectionModuleBuilder *mb, HANDLE file, MonoErro } /* check that the file is properly padded */ - if (SetFilePointer (file, file_offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - g_error ("SetFilePointer returned %d\n", GetLastError ()); - if (! SetEndOfFile (file)) - g_error ("SetEndOfFile returned %d\n", GetLastError ()); + if (mono_w32file_seek (file, file_offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + g_error ("mono_w32file_seek returned %d\n", GetLastError ()); + if (! mono_w32file_truncate (file)) + g_error ("mono_w32file_truncate returned %d\n", GetLastError ()); mono_dynamic_stream_reset (&assembly->code); mono_dynamic_stream_reset (&assembly->us); diff --git a/mono/metadata/threads-types.h b/mono/metadata/threads-types.h index 4387f013cdb..626a26bb31b 100644 --- a/mono/metadata/threads-types.h +++ b/mono/metadata/threads-types.h @@ -53,10 +53,6 @@ typedef enum { #define SPECIAL_STATIC_THREAD 1 #define SPECIAL_STATIC_CONTEXT 2 -#ifdef HOST_WIN32 -typedef SECURITY_ATTRIBUTES WapiSecurityAttributes; -#endif - typedef struct _MonoInternalThread MonoInternalThread; typedef void (*MonoThreadCleanupFunc) (MonoNativeThreadId tid); diff --git a/mono/metadata/w32event-unix.c b/mono/metadata/w32event-unix.c index af5b890d162..8c9b1b1f765 100644 --- a/mono/metadata/w32event-unix.c +++ b/mono/metadata/w32event-unix.c @@ -14,6 +14,8 @@ #include "mono/utils/mono-logger-internals.h" #include "mono/metadata/w32handle.h" +#define MAX_PATH 260 + typedef struct { gboolean manual; guint32 set_count; diff --git a/mono/metadata/w32file-internals.h b/mono/metadata/w32file-internals.h new file mode 100644 index 00000000000..0458a64d30b --- /dev/null +++ b/mono/metadata/w32file-internals.h @@ -0,0 +1,11 @@ +/* + * Copyright 2016 Microsoft + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ +#ifndef _MONO_METADATA_W32FILE_INTERNALS_H_ +#define _MONO_METADATA_W32FILE_INTERNALS_H_ + +#include +#include + +#endif /* _MONO_METADATA_W32FILE_INTERNALS_H_ */ diff --git a/mono/io-layer/wapi_glob.c b/mono/metadata/w32file-unix-glob.c similarity index 80% rename from mono/io-layer/wapi_glob.c rename to mono/metadata/w32file-unix-glob.c index 013b778a865..99e02a47e0b 100644 --- a/mono/io-layer/wapi_glob.c +++ b/mono/metadata/w32file-unix-glob.c @@ -32,7 +32,7 @@ */ /* - * _wapi_glob(3) -- a subset of the one defined in POSIX 1003.2. + * mono_w32file_unix_glob(3) -- a subset of the one defined in POSIX 1003.2. * * Optional extra services, controlled by flags not defined by POSIX: * @@ -50,7 +50,7 @@ #include #include -#include "wapi_glob.h" +#include "w32file-unix-glob.h" #define EOS '\0' #define NOT '!' @@ -86,33 +86,41 @@ typedef char Char; #define ismeta(c) (((c)&M_QUOTE) != 0) -static int g_Ctoc(const gchar *, char *, unsigned int); -static int glob0(GDir *dir, const gchar *, wapi_glob_t *, gboolean, - gboolean); -static int glob1(GDir *dir, gchar *, gchar *, wapi_glob_t *, size_t *, - gboolean, gboolean); -static int glob3(GDir *dir, gchar *, gchar *, wapi_glob_t *, size_t *, - gboolean, gboolean); -static int globextend(const gchar *, wapi_glob_t *, size_t *); -static int match(const gchar *, gchar *, gchar *, gboolean); +static int +g_Ctoc(const gchar *, char *, unsigned int); + +static int +glob0(GDir *dir, const gchar *, mono_w32file_unix_glob_t *, gboolean, gboolean); +static int +glob1(GDir *dir, gchar *, gchar *, mono_w32file_unix_glob_t *, size_t *, gboolean, gboolean); + +static int +glob3(GDir *dir, gchar *, gchar *, mono_w32file_unix_glob_t *, size_t *, gboolean, gboolean); + +static int +globextend(const gchar *, mono_w32file_unix_glob_t *, size_t *); + +static int +match(const gchar *, gchar *, gchar *, gboolean); + #ifdef DEBUG_ENABLED static void qprintf(const char *, Char *); #endif int -_wapi_glob(GDir *dir, const char *pattern, int flags, wapi_glob_t *pglob) +mono_w32file_unix_glob(GDir *dir, const char *pattern, int flags, mono_w32file_unix_glob_t *pglob) { const unsigned char *patnext; int c; gchar *bufnext, *bufend, patbuf[PATH_MAX]; patnext = (unsigned char *) pattern; - if (!(flags & WAPI_GLOB_APPEND)) { + if (!(flags & W32FILE_UNIX_GLOB_APPEND)) { pglob->gl_pathc = 0; pglob->gl_pathv = NULL; pglob->gl_offs = 0; } - pglob->gl_flags = flags & ~WAPI_GLOB_MAGCHAR; + pglob->gl_flags = flags & ~W32FILE_UNIX_GLOB_MAGCHAR; bufnext = patbuf; bufend = bufnext + PATH_MAX - 1; @@ -130,8 +138,8 @@ _wapi_glob(GDir *dir, const char *pattern, int flags, wapi_glob_t *pglob) *bufnext = EOS; - return glob0(dir, patbuf, pglob, flags & WAPI_GLOB_IGNORECASE, - flags & WAPI_GLOB_UNIQUE); + return glob0(dir, patbuf, pglob, flags & W32FILE_UNIX_GLOB_IGNORECASE, + flags & W32FILE_UNIX_GLOB_UNIQUE); } /* @@ -142,7 +150,7 @@ _wapi_glob(GDir *dir, const char *pattern, int flags, wapi_glob_t *pglob) * to find no matches. */ static int -glob0(GDir *dir, const gchar *pattern, wapi_glob_t *pglob, gboolean ignorecase, +glob0(GDir *dir, const gchar *pattern, mono_w32file_unix_glob_t *pglob, gboolean ignorecase, gboolean unique) { const gchar *qpatnext; @@ -158,11 +166,11 @@ glob0(GDir *dir, const gchar *pattern, wapi_glob_t *pglob, gboolean ignorecase, while ((c = *qpatnext++) != EOS) { switch (c) { case QUESTION: - pglob->gl_flags |= WAPI_GLOB_MAGCHAR; + pglob->gl_flags |= W32FILE_UNIX_GLOB_MAGCHAR; *bufnext++ = M_ONE; break; case STAR: - pglob->gl_flags |= WAPI_GLOB_MAGCHAR; + pglob->gl_flags |= W32FILE_UNIX_GLOB_MAGCHAR; /* collapse adjacent stars to one, * to avoid exponential behavior */ @@ -184,14 +192,14 @@ glob0(GDir *dir, const gchar *pattern, wapi_glob_t *pglob, gboolean ignorecase, return(err); if (pglob->gl_pathc == oldpathc) { - return(WAPI_GLOB_NOMATCH); + return(W32FILE_UNIX_GLOB_NOMATCH); } return(0); } static int -glob1(GDir *dir, gchar *pattern, gchar *pattern_last, wapi_glob_t *pglob, +glob1(GDir *dir, gchar *pattern, gchar *pattern_last, mono_w32file_unix_glob_t *pglob, size_t *limitp, gboolean ignorecase, gboolean unique) { /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ @@ -201,7 +209,7 @@ glob1(GDir *dir, gchar *pattern, gchar *pattern_last, wapi_glob_t *pglob, unique)); } -static gboolean contains (wapi_glob_t *pglob, const gchar *name) +static gboolean contains (mono_w32file_unix_glob_t *pglob, const gchar *name) { int i; char **pp; @@ -221,7 +229,7 @@ static gboolean contains (wapi_glob_t *pglob, const gchar *name) } static int -glob3(GDir *dir, gchar *pattern, gchar *pattern_last, wapi_glob_t *pglob, +glob3(GDir *dir, gchar *pattern, gchar *pattern_last, mono_w32file_unix_glob_t *pglob, size_t *limitp, gboolean ignorecase, gboolean unique) { const gchar *name; @@ -243,7 +251,7 @@ glob3(GDir *dir, gchar *pattern, gchar *pattern_last, wapi_glob_t *pglob, /* - * Extend the gl_pathv member of a wapi_glob_t structure to accommodate a new item, + * Extend the gl_pathv member of a mono_w32file_unix_glob_t structure to accommodate a new item, * add the new item, and update gl_pathc. * * This assumes the BSD realloc, which only copies the block when its size @@ -252,12 +260,12 @@ glob3(GDir *dir, gchar *pattern, gchar *pattern_last, wapi_glob_t *pglob, * * Return 0 if new item added, error code if memory couldn't be allocated. * - * Invariant of the wapi_glob_t structure: + * Invariant of the mono_w32file_unix_glob_t structure: * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and * gl_pathv points to (gl_offs + gl_pathc + 1) items. */ static int -globextend(const gchar *path, wapi_glob_t *pglob, size_t *limitp) +globextend(const gchar *path, mono_w32file_unix_glob_t *pglob, size_t *limitp) { char **pathv; int i; @@ -274,7 +282,7 @@ globextend(const gchar *path, wapi_glob_t *pglob, size_t *limitp) g_free (pglob->gl_pathv); pglob->gl_pathv = NULL; } - return(WAPI_GLOB_NOSPACE); + return(W32FILE_UNIX_GLOB_NOSPACE); } if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { @@ -292,7 +300,7 @@ globextend(const gchar *path, wapi_glob_t *pglob, size_t *limitp) if ((copy = (char *)malloc(len)) != NULL) { if (g_Ctoc(path, copy, len)) { g_free (copy); - return(WAPI_GLOB_NOSPACE); + return(W32FILE_UNIX_GLOB_NOSPACE); } pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; } @@ -300,14 +308,14 @@ globextend(const gchar *path, wapi_glob_t *pglob, size_t *limitp) #if 0 /* Broken on opensuse 11 */ - if ((pglob->gl_flags & WAPI_GLOB_LIMIT) && + if ((pglob->gl_flags & W32FILE_UNIX_GLOB_LIMIT) && newsize + *limitp >= ARG_MAX) { errno = 0; - return(WAPI_GLOB_NOSPACE); + return(W32FILE_UNIX_GLOB_NOSPACE); } #endif - return(copy == NULL ? WAPI_GLOB_NOSPACE : 0); + return(copy == NULL ? W32FILE_UNIX_GLOB_NOSPACE : 0); } @@ -350,9 +358,9 @@ match(const gchar *name, gchar *pat, gchar *patend, gboolean ignorecase) return(*name == EOS); } -/* Free allocated data belonging to a wapi_glob_t structure. */ +/* Free allocated data belonging to a mono_w32file_unix_glob_t structure. */ void -_wapi_globfree(wapi_glob_t *pglob) +mono_w32file_unix_globfree(mono_w32file_unix_glob_t *pglob) { int i; char **pp; diff --git a/mono/io-layer/wapi_glob.h b/mono/metadata/w32file-unix-glob.h similarity index 65% rename from mono/io-layer/wapi_glob.h rename to mono/metadata/w32file-unix-glob.h index fc9d7ba8870..b1923089625 100644 --- a/mono/io-layer/wapi_glob.h +++ b/mono/metadata/w32file-unix-glob.h @@ -35,8 +35,8 @@ * @(#)glob.h 8.1 (Berkeley) 6/2/93 */ -#ifndef _WAPI_GLOB_H_ -#define _WAPI_GLOB_H_ +#ifndef __MONO_METADATA_W32FILE_UNIX_GLOB_H__ +#define __MONO_METADATA_W32FILE_UNIX_GLOB_H__ #include @@ -46,23 +46,28 @@ typedef struct { int gl_offs; /* Reserved at beginning of gl_pathv. */ int gl_flags; /* Copy of flags parameter to glob. */ char **gl_pathv; /* List of paths matching pattern. */ -} wapi_glob_t; +} mono_w32file_unix_glob_t; -#define WAPI_GLOB_APPEND 0x0001 /* Append to output from previous call. */ -#define WAPI_GLOB_UNIQUE 0x0040 /* When appending only add items that aren't already in the list */ -#define WAPI_GLOB_NOSPACE (-1) /* Malloc call failed. */ -#define WAPI_GLOB_ABORTED (-2) /* Unignored error. */ -#define WAPI_GLOB_NOMATCH (-3) /* No match and WAPI_GLOB_NOCHECK not set. */ -#define WAPI_GLOB_NOSYS (-4) /* Function not supported. */ +#define W32FILE_UNIX_GLOB_APPEND 0x0001 /* Append to output from previous call. */ +#define W32FILE_UNIX_GLOB_UNIQUE 0x0040 /* When appending only add items that aren't already in the list */ +#define W32FILE_UNIX_GLOB_NOSPACE (-1) /* Malloc call failed. */ +#define W32FILE_UNIX_GLOB_ABORTED (-2) /* Unignored error. */ +#define W32FILE_UNIX_GLOB_NOMATCH (-3) /* No match and W32FILE_UNIX_GLOB_NOCHECK not set. */ +#define W32FILE_UNIX_GLOB_NOSYS (-4) /* Function not supported. */ -#define WAPI_GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ -#define WAPI_GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ -#define WAPI_GLOB_IGNORECASE 0x4000 /* Ignore case when matching */ -#define WAPI_GLOB_ABEND WAPI_GLOB_ABORTED /* backward compatibility */ +#define W32FILE_UNIX_GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ +#define W32FILE_UNIX_GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ +#define W32FILE_UNIX_GLOB_IGNORECASE 0x4000 /* Ignore case when matching */ +#define W32FILE_UNIX_GLOB_ABEND W32FILE_UNIX_GLOB_ABORTED /* backward compatibility */ G_BEGIN_DECLS -int _wapi_glob(GDir *dir, const char *, int, wapi_glob_t *); -void _wapi_globfree(wapi_glob_t *); + +int +mono_w32file_unix_glob (GDir *dir, const char *, int, mono_w32file_unix_glob_t *); + +void +mono_w32file_unix_globfree (mono_w32file_unix_glob_t *); + G_END_DECLS -#endif /* !_WAPI_GLOB_H_ */ +#endif /* !__MONO_METADATA_W32FILE_UNIX_GLOB_H__ */ diff --git a/mono/io-layer/io.c b/mono/metadata/w32file-unix.c similarity index 69% rename from mono/io-layer/io.c rename to mono/metadata/w32file-unix.c index 05d554a12c0..ecca05ec6aa 100644 --- a/mono/io-layer/io.c +++ b/mono/metadata/w32file-unix.c @@ -1,17 +1,8 @@ -/* - * io.c: File, console and find handles - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - * Copyright (c) 2002-2006 Novell, Inc. - * Copyright 2011 Xamarin Inc (http://www.xamarin.com). - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ #include #include + +#include #include #include #include @@ -35,27 +26,62 @@ #include #include #endif +#include +#ifdef HAVE_DIRENT_H +# include +#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "w32file.h" +#include "w32file-internals.h" + +#include "w32file-unix-glob.h" +#include "w32handle.h" +#include "utils/mono-io-portability.h" +#include "utils/mono-logger-internals.h" +#include "utils/mono-os-mutex.h" +#include "utils/mono-threads.h" +#include "utils/mono-threads-api.h" +#include "utils/strenc.h" + +typedef struct { + guint64 device; + guint64 inode; + pid_t opened_by_pid; + guint32 sharemode; + guint32 access; + guint32 handle_refs; + guint32 timestamp; +} FileShare; + +/* Currently used for both FILE, CONSOLE and PIPE handle types. + * This may have to change in future. */ +typedef struct { + gchar *filename; + FileShare *share_info; /* Pointer into shared mem */ + gint fd; + guint32 security_attributes; + guint32 fileaccess; + guint32 sharemode; + guint32 attrs; +} MonoW32HandleFile; + +typedef struct { + gchar **namelist; + gchar *dir_part; + gint num; + gsize count; +} MonoW32HandleFind; /* - * If SHM is disabled, this will point to a hash of _WapiFileShare structures, otherwise + * If SHM is disabled, this will point to a hash of FileShare structures, otherwise * it will be NULL. We use this instead of _wapi_fileshare_layout to avoid allocating a * 4MB array. */ -static GHashTable *file_share_hash; +static GHashTable *file_share_table; static mono_mutex_t file_share_mutex; static void -time_t_to_filetime (time_t timeval, WapiFileTime *filetime) +time_t_to_filetime (time_t timeval, FILETIME *filetime) { guint64 ticks; @@ -65,7 +91,7 @@ time_t_to_filetime (time_t timeval, WapiFileTime *filetime) } static void -_wapi_handle_share_release (_WapiFileShare *share_info) +file_share_release (FileShare *share_info) { /* Prevent new entries racing with us */ mono_os_mutex_lock (&file_share_mutex); @@ -74,52 +100,52 @@ _wapi_handle_share_release (_WapiFileShare *share_info) share_info->handle_refs -= 1; if (share_info->handle_refs == 0) - g_hash_table_remove (file_share_hash, share_info); + g_hash_table_remove (file_share_table, share_info); mono_os_mutex_unlock (&file_share_mutex); } static gint -wapi_share_info_equal (gconstpointer ka, gconstpointer kb) +file_share_equal (gconstpointer ka, gconstpointer kb) { - const _WapiFileShare *s1 = (const _WapiFileShare *)ka; - const _WapiFileShare *s2 = (const _WapiFileShare *)kb; + const FileShare *s1 = (const FileShare *)ka; + const FileShare *s2 = (const FileShare *)kb; return (s1->device == s2->device && s1->inode == s2->inode) ? 1 : 0; } static guint -wapi_share_info_hash (gconstpointer data) +file_share_hash (gconstpointer data) { - const _WapiFileShare *s = (const _WapiFileShare *)data; + const FileShare *s = (const FileShare *)data; return s->inode; } static gboolean -_wapi_handle_get_or_set_share (guint64 device, guint64 inode, guint32 new_sharemode, guint32 new_access, - guint32 *old_sharemode, guint32 *old_access, struct _WapiFileShare **share_info) +file_share_get (guint64 device, guint64 inode, guint32 new_sharemode, guint32 new_access, + guint32 *old_sharemode, guint32 *old_access, FileShare **share_info) { - struct _WapiFileShare *file_share; + FileShare *file_share; gboolean exists = FALSE; /* Prevent new entries racing with us */ mono_os_mutex_lock (&file_share_mutex); - _WapiFileShare tmp; + FileShare tmp; /* * Instead of allocating a 4MB array, we use a hash table to keep track of this * info. This is needed even if SHM is disabled, to track sharing inside * the current process. */ - if (!file_share_hash) - file_share_hash = g_hash_table_new_full (wapi_share_info_hash, wapi_share_info_equal, NULL, g_free); + if (!file_share_table) + file_share_table = g_hash_table_new_full (file_share_hash, file_share_equal, NULL, g_free); tmp.device = device; tmp.inode = inode; - file_share = (_WapiFileShare *)g_hash_table_lookup (file_share_hash, &tmp); + file_share = (FileShare *)g_hash_table_lookup (file_share_table, &tmp); if (file_share) { *old_sharemode = file_share->sharemode; *old_access = file_share->access; @@ -130,7 +156,7 @@ _wapi_handle_get_or_set_share (guint64 device, guint64 inode, guint32 new_sharem exists = TRUE; } else { - file_share = g_new0 (_WapiFileShare, 1); + file_share = g_new0 (FileShare, 1); file_share->device = device; file_share->inode = inode; @@ -140,7 +166,7 @@ _wapi_handle_get_or_set_share (guint64 device, guint64 inode, guint32 new_sharem file_share->handle_refs = 1; *share_info = file_share; - g_hash_table_insert (file_share_hash, file_share, file_share); + g_hash_table_insert (file_share_table, file_share, file_share); } mono_os_mutex_unlock (&file_share_mutex); @@ -148,29 +174,607 @@ _wapi_handle_get_or_set_share (guint64 device, guint64 inode, guint32 new_sharem return(exists); } +static gint +_wapi_open (const gchar *pathname, gint flags, mode_t mode) +{ + gint fd; + gchar *located_filename; + + if (flags & O_CREAT) { + located_filename = mono_portability_find_file (pathname, FALSE); + if (located_filename == NULL) { + fd = open (pathname, flags, mode); + } else { + fd = open (located_filename, flags, mode); + g_free (located_filename); + } + } else { + fd = open (pathname, flags, mode); + if (fd == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + located_filename = mono_portability_find_file (pathname, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + fd = open (located_filename, flags, mode); + g_free (located_filename); + } + } + + return(fd); +} + +static gint +_wapi_access (const gchar *pathname, gint mode) +{ + gint ret; + + ret = access (pathname, mode); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (pathname, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = access (located_filename, mode); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_chmod (const gchar *pathname, mode_t mode) +{ + gint ret; + + ret = chmod (pathname, mode); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (pathname, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = chmod (located_filename, mode); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_utime (const gchar *filename, const struct utimbuf *buf) +{ + gint ret; + + ret = utime (filename, buf); + if (ret == -1 && errno == ENOENT && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (filename, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = utime (located_filename, buf); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_unlink (const gchar *pathname) +{ + gint ret; + + ret = unlink (pathname); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR || errno == EISDIR) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (pathname, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = unlink (located_filename); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_rename (const gchar *oldpath, const gchar *newpath) +{ + gint ret; + gchar *located_newpath = mono_portability_find_file (newpath, FALSE); + + if (located_newpath == NULL) { + ret = rename (oldpath, newpath); + } else { + ret = rename (oldpath, located_newpath); + + if (ret == -1 && (errno == EISDIR || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EXDEV) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_oldpath = mono_portability_find_file (oldpath, TRUE); + + if (located_oldpath == NULL) { + g_free (located_oldpath); + g_free (located_newpath); + + errno = saved_errno; + return -1; + } + + ret = rename (located_oldpath, located_newpath); + g_free (located_oldpath); + } + g_free (located_newpath); + } + + return ret; +} + +static gint +_wapi_stat (const gchar *path, struct stat *buf) +{ + gint ret; + + ret = stat (path, buf); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (path, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = stat (located_filename, buf); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_lstat (const gchar *path, struct stat *buf) +{ + gint ret; + + ret = lstat (path, buf); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (path, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = lstat (located_filename, buf); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_mkdir (const gchar *pathname, mode_t mode) +{ + gint ret; + gchar *located_filename = mono_portability_find_file (pathname, FALSE); + + if (located_filename == NULL) { + ret = mkdir (pathname, mode); + } else { + ret = mkdir (located_filename, mode); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_rmdir (const gchar *pathname) +{ + gint ret; + + ret = rmdir (pathname); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (pathname, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = rmdir (located_filename); + g_free (located_filename); + } + + return ret; +} + +static gint +_wapi_chdir (const gchar *path) +{ + gint ret; + + ret = chdir (path); + if (ret == -1 && (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) && IS_PORTABILITY_SET) { + gint saved_errno = errno; + gchar *located_filename = mono_portability_find_file (path, TRUE); + + if (located_filename == NULL) { + errno = saved_errno; + return -1; + } + + ret = chdir (located_filename); + g_free (located_filename); + } + + return ret; +} + +static gchar* +_wapi_basename (const gchar *filename) +{ + gchar *new_filename = g_strdup (filename), *ret; + + if (IS_PORTABILITY_SET) { + g_strdelimit (new_filename, "\\", '/'); + } + + if (IS_PORTABILITY_DRIVE && g_ascii_isalpha (new_filename[0]) && (new_filename[1] == ':')) { + gint len = strlen (new_filename); + + g_memmove (new_filename, new_filename + 2, len - 2); + new_filename[len - 2] = '\0'; + } + + ret = g_path_get_basename (new_filename); + g_free (new_filename); + + return ret; +} + +static gchar* +_wapi_dirname (const gchar *filename) +{ + gchar *new_filename = g_strdup (filename), *ret; + + if (IS_PORTABILITY_SET) { + g_strdelimit (new_filename, "\\", '/'); + } + + if (IS_PORTABILITY_DRIVE && g_ascii_isalpha (new_filename[0]) && (new_filename[1] == ':')) { + gint len = strlen (new_filename); + + g_memmove (new_filename, new_filename + 2, len - 2); + new_filename[len - 2] = '\0'; + } + + ret = g_path_get_dirname (new_filename); + g_free (new_filename); + + return ret; +} + +static GDir* +_wapi_g_dir_open (const gchar *path, guint flags, GError **error) +{ + GDir *ret; + + ret = g_dir_open (path, flags, error); + if (ret == NULL && ((*error)->code == G_FILE_ERROR_NOENT || (*error)->code == G_FILE_ERROR_NOTDIR || (*error)->code == G_FILE_ERROR_NAMETOOLONG) && IS_PORTABILITY_SET) { + gchar *located_filename = mono_portability_find_file (path, TRUE); + GError *tmp_error = NULL; + + if (located_filename == NULL) { + return(NULL); + } + + ret = g_dir_open (located_filename, flags, &tmp_error); + g_free (located_filename); + if (tmp_error == NULL) { + g_clear_error (error); + } + } + + return ret; +} + +static gint +get_errno_from_g_file_error (gint error) +{ + switch (error) { +#ifdef EACCESS + case G_FILE_ERROR_ACCES: return EACCES; +#endif +#ifdef ENAMETOOLONG + case G_FILE_ERROR_NAMETOOLONG: return ENAMETOOLONG; +#endif +#ifdef ENOENT + case G_FILE_ERROR_NOENT: return ENOENT; +#endif +#ifdef ENOTDIR + case G_FILE_ERROR_NOTDIR: return ENOTDIR; +#endif +#ifdef ENXIO + case G_FILE_ERROR_NXIO: return ENXIO; +#endif +#ifdef ENODEV + case G_FILE_ERROR_NODEV: return ENODEV; +#endif +#ifdef EROFS + case G_FILE_ERROR_ROFS: return EROFS; +#endif +#ifdef ETXTBSY + case G_FILE_ERROR_TXTBSY: return ETXTBSY; +#endif +#ifdef EFAULT + case G_FILE_ERROR_FAULT: return EFAULT; +#endif +#ifdef ELOOP + case G_FILE_ERROR_LOOP: return ELOOP; +#endif +#ifdef ENOSPC + case G_FILE_ERROR_NOSPC: return ENOSPC; +#endif +#ifdef ENOMEM + case G_FILE_ERROR_NOMEM: return ENOMEM; +#endif +#ifdef EMFILE + case G_FILE_ERROR_MFILE: return EMFILE; +#endif +#ifdef ENFILE + case G_FILE_ERROR_NFILE: return ENFILE; +#endif +#ifdef EBADF + case G_FILE_ERROR_BADF: return EBADF; +#endif +#ifdef EINVAL + case G_FILE_ERROR_INVAL: return EINVAL; +#endif +#ifdef EPIPE + case G_FILE_ERROR_PIPE: return EPIPE; +#endif +#ifdef EAGAIN + case G_FILE_ERROR_AGAIN: return EAGAIN; +#endif +#ifdef EINTR + case G_FILE_ERROR_INTR: return EINTR; +#endif +#ifdef EWIO + case G_FILE_ERROR_IO: return EIO; +#endif +#ifdef EPERM + case G_FILE_ERROR_PERM: return EPERM; +#endif + case G_FILE_ERROR_FAILED: return ERROR_INVALID_PARAMETER; + default: + g_assert_not_reached (); + } +} + +static gint +file_compare (gconstpointer a, gconstpointer b) +{ + gchar *astr = *(gchar **) a; + gchar *bstr = *(gchar **) b; + + return strcmp (astr, bstr); +} + +/* scandir using glib */ +static gint +_wapi_io_scandir (const gchar *dirname, const gchar *pattern, gchar ***namelist) +{ + GError *error = NULL; + GDir *dir; + GPtrArray *names; + gint result; + mono_w32file_unix_glob_t glob_buf; + gint flags = 0, i; + + dir = _wapi_g_dir_open (dirname, 0, &error); + if (dir == NULL) { + /* g_dir_open returns ENOENT on directories on which we don't + * have read/x permission */ + gint errnum = get_errno_from_g_file_error (error->code); + g_error_free (error); + if (errnum == ENOENT && + !_wapi_access (dirname, F_OK) && + _wapi_access (dirname, R_OK|X_OK)) { + errnum = EACCES; + } + + errno = errnum; + return -1; + } + + if (IS_PORTABILITY_CASE) { + flags = W32FILE_UNIX_GLOB_IGNORECASE; + } + + result = mono_w32file_unix_glob (dir, pattern, flags, &glob_buf); + if (g_str_has_suffix (pattern, ".*")) { + /* Special-case the patterns ending in '.*', as + * windows also matches entries with no extension with + * this pattern. + * + * TODO: should this be a MONO_IOMAP option? + */ + gchar *pattern2 = g_strndup (pattern, strlen (pattern) - 2); + gint result2; + + g_dir_rewind (dir); + result2 = mono_w32file_unix_glob (dir, pattern2, flags | W32FILE_UNIX_GLOB_APPEND | W32FILE_UNIX_GLOB_UNIQUE, &glob_buf); + + g_free (pattern2); + + if (result != 0) { + result = result2; + } + } + + g_dir_close (dir); + if (glob_buf.gl_pathc == 0) { + return(0); + } else if (result != 0) { + return -1; + } + + names = g_ptr_array_new (); + for (i = 0; i < glob_buf.gl_pathc; i++) { + g_ptr_array_add (names, g_strdup (glob_buf.gl_pathv[i])); + } + + mono_w32file_unix_globfree (&glob_buf); + + result = names->len; + if (result > 0) { + g_ptr_array_sort (names, file_compare); + g_ptr_array_set_size (names, result + 1); + + *namelist = (gchar **) g_ptr_array_free (names, FALSE); + } else { + g_ptr_array_free (names, TRUE); + } + + return result; +} + +static gboolean +_wapi_lock_file_region (gint fd, off_t offset, off_t length) +{ +#if defined(__native_client__) + printf("WARNING: %s: fcntl() not available on Native Client!\n", __func__); + // behave as below -- locks are not available + return TRUE; +#else + struct flock lock_data; + gint ret; + + if (offset < 0 || length < 0) { + SetLastError (ERROR_INVALID_PARAMETER); + return FALSE; + } + + lock_data.l_type = F_WRLCK; + lock_data.l_whence = SEEK_SET; + lock_data.l_start = offset; + lock_data.l_len = length; + + do { + ret = fcntl (fd, F_SETLK, &lock_data); + } while(ret == -1 && errno == EINTR); + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl returns %d", __func__, ret); + + if (ret == -1) { + /* + * if locks are not available (NFS for example), + * ignore the error + */ + if (errno == ENOLCK +#ifdef EOPNOTSUPP + || errno == EOPNOTSUPP +#endif +#ifdef ENOTSUP + || errno == ENOTSUP +#endif + ) { + return TRUE; + } + + SetLastError (ERROR_LOCK_VIOLATION); + return FALSE; + } + + return TRUE; +#endif /* __native_client__ */ +} + +static gboolean +_wapi_unlock_file_region (gint fd, off_t offset, off_t length) +{ +#if defined(__native_client__) + printf("WARNING: %s: fcntl() not available on Native Client!\n", __func__); + return TRUE; +#else + struct flock lock_data; + gint ret; + + lock_data.l_type = F_UNLCK; + lock_data.l_whence = SEEK_SET; + lock_data.l_start = offset; + lock_data.l_len = length; + + do { + ret = fcntl (fd, F_SETLK, &lock_data); + } while(ret == -1 && errno == EINTR); + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl returns %d", __func__, ret); + + if (ret == -1) { + /* + * if locks are not available (NFS for example), + * ignore the error + */ + if (errno == ENOLCK +#ifdef EOPNOTSUPP + || errno == EOPNOTSUPP +#endif +#ifdef ENOTSUP + || errno == ENOTSUP +#endif + ) { + return TRUE; + } + + SetLastError (ERROR_LOCK_VIOLATION); + return FALSE; + } + + return TRUE; +#endif /* __native_client__ */ +} + static void file_close (gpointer handle, gpointer data); static void file_details (gpointer data); static const gchar* file_typename (void); static gsize file_typesize (void); -static WapiFileType file_getfiletype(void); -static gboolean file_read(gpointer handle, gpointer buffer, - guint32 numbytes, guint32 *bytesread, - WapiOverlapped *overlapped); -static gboolean file_write(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped); +static gint file_getfiletype(void); +static gboolean file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread); +static gboolean file_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten); static gboolean file_flush(gpointer handle); static guint32 file_seek(gpointer handle, gint32 movedistance, - gint32 *highmovedistance, WapiSeekMethod method); + gint32 *highmovedistance, gint method); static gboolean file_setendoffile(gpointer handle); static guint32 file_getfilesize(gpointer handle, guint32 *highsize); -static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time, - WapiFileTime *last_access, - WapiFileTime *last_write); +static gboolean file_getfiletime(gpointer handle, FILETIME *create_time, + FILETIME *access_time, + FILETIME *write_time); static gboolean file_setfiletime(gpointer handle, - const WapiFileTime *create_time, - const WapiFileTime *last_access, - const WapiFileTime *last_write); + const FILETIME *create_time, + const FILETIME *access_time, + const FILETIME *write_time); static guint32 GetDriveTypeFromPath (const gchar *utf8_root_path_name); /* File handle is only signalled for overlapped IO */ @@ -190,13 +794,9 @@ static void console_close (gpointer handle, gpointer data); static void console_details (gpointer data); static const gchar* console_typename (void); static gsize console_typesize (void); -static WapiFileType console_getfiletype(void); -static gboolean console_read(gpointer handle, gpointer buffer, - guint32 numbytes, guint32 *bytesread, - WapiOverlapped *overlapped); -static gboolean console_write(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped); +static gint console_getfiletype(void); +static gboolean console_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread); +static gboolean console_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten); /* Console is mostly the same as file, except it can block waiting for * input or output @@ -232,12 +832,9 @@ static void pipe_close (gpointer handle, gpointer data); static void pipe_details (gpointer data); static const gchar* pipe_typename (void); static gsize pipe_typesize (void); -static WapiFileType pipe_getfiletype (void); -static gboolean pipe_read (gpointer handle, gpointer buffer, guint32 numbytes, - guint32 *bytesread, WapiOverlapped *overlapped); -static gboolean pipe_write (gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped); +static gint pipe_getfiletype (void); +static gboolean pipe_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread); +static gboolean pipe_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten); /* Pipe handles */ @@ -255,29 +852,25 @@ static MonoW32HandleOps _wapi_pipe_ops = { static const struct { /* File, console and pipe handles */ - WapiFileType (*getfiletype)(void); + gint (*getfiletype)(void); /* File, console and pipe handles */ - gboolean (*readfile)(gpointer handle, gpointer buffer, - guint32 numbytes, guint32 *bytesread, - WapiOverlapped *overlapped); - gboolean (*writefile)(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped); + gboolean (*readfile)(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread); + gboolean (*writefile)(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten); gboolean (*flushfile)(gpointer handle); /* File handles */ guint32 (*seek)(gpointer handle, gint32 movedistance, - gint32 *highmovedistance, WapiSeekMethod method); + gint32 *highmovedistance, gint method); gboolean (*setendoffile)(gpointer handle); guint32 (*getfilesize)(gpointer handle, guint32 *highsize); - gboolean (*getfiletime)(gpointer handle, WapiFileTime *create_time, - WapiFileTime *last_access, - WapiFileTime *last_write); + gboolean (*getfiletime)(gpointer handle, FILETIME *create_time, + FILETIME *access_time, + FILETIME *write_time); gboolean (*setfiletime)(gpointer handle, - const WapiFileTime *create_time, - const WapiFileTime *last_access, - const WapiFileTime *last_write); + const FILETIME *create_time, + const FILETIME *access_time, + const FILETIME *write_time); } io_ops[MONO_W32HANDLE_COUNT]={ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, /* file */ @@ -335,7 +928,7 @@ static gboolean lock_while_writing = FALSE; * and should not be used with a dynamic runtime. */ static gboolean -is_file_writable (struct stat *st, const char *path) +is_file_writable (struct stat *st, const gchar *path) { #if __APPLE__ // OS X Finder "locked" or `ls -lO` "uchg". @@ -451,10 +1044,10 @@ static void _wapi_set_last_path_error_from_errno (const gchar *dir, */ static void file_close (gpointer handle, gpointer data) { - struct _WapiHandle_file *file_handle = (struct _WapiHandle_file *)data; - int fd = file_handle->fd; + MonoW32HandleFile *file_handle = (MonoW32HandleFile *)data; + gint fd = file_handle->fd; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing file handle %p [%s]", __func__, handle, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing file handle %p [%s]", __func__, handle, file_handle->filename); if (file_handle->attrs & FILE_FLAG_DELETE_ON_CLOSE) @@ -463,14 +1056,14 @@ static void file_close (gpointer handle, gpointer data) g_free (file_handle->filename); if (file_handle->share_info) - _wapi_handle_share_release (file_handle->share_info); + file_share_release (file_handle->share_info); close (fd); } static void file_details (gpointer data) { - struct _WapiHandle_file *file = (struct _WapiHandle_file *)data; + MonoW32HandleFile *file = (MonoW32HandleFile *)data; g_print ("[%20s] acc: %c%c%c, shr: %c%c%c, attrs: %5u", file->filename, @@ -490,21 +1083,20 @@ static const gchar* file_typename (void) static gsize file_typesize (void) { - return sizeof (struct _WapiHandle_file); + return sizeof (MonoW32HandleFile); } -static WapiFileType file_getfiletype(void) +static gint file_getfiletype(void) { return(FILE_TYPE_DISK); } -static gboolean file_read(gpointer handle, gpointer buffer, - guint32 numbytes, guint32 *bytesread, - WapiOverlapped *overlapped) +static gboolean +file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; - int fd, ret; + gint fd, ret; MonoThreadInfo *info = mono_thread_info_current (); ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, @@ -523,7 +1115,7 @@ static gboolean file_read(gpointer handle, gpointer buffer, if(!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); @@ -538,7 +1130,7 @@ static gboolean file_read(gpointer handle, gpointer buffer, if(ret==-1) { gint err = errno; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, handle, strerror(err)); SetLastError (_wapi_get_win32_file_error (err)); return(FALSE); @@ -551,13 +1143,12 @@ static gboolean file_read(gpointer handle, gpointer buffer, return(TRUE); } -static gboolean file_write(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped G_GNUC_UNUSED) +static gboolean +file_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; - int ret, fd; + gint ret, fd; off_t current_pos = 0; MonoThreadInfo *info = mono_thread_info_current (); @@ -578,7 +1169,7 @@ static gboolean file_write(gpointer handle, gconstpointer buffer, if(!(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); @@ -591,7 +1182,7 @@ static gboolean file_write(gpointer handle, gconstpointer buffer, */ current_pos = lseek (fd, (off_t)0, SEEK_CUR); if (current_pos == -1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p lseek failed: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p lseek failed: %s", __func__, handle, strerror (errno)); _wapi_set_last_error_from_errno (); return(FALSE); @@ -619,7 +1210,7 @@ static gboolean file_write(gpointer handle, gconstpointer buffer, } else { _wapi_set_last_error_from_errno (); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write of handle %p error: %s", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write of handle %p error: %s", __func__, handle, strerror(errno)); return(FALSE); @@ -633,9 +1224,9 @@ static gboolean file_write(gpointer handle, gconstpointer buffer, static gboolean file_flush(gpointer handle) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; - int ret, fd; + gint ret, fd; ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle); @@ -650,7 +1241,7 @@ static gboolean file_flush(gpointer handle) if(!(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); @@ -658,7 +1249,7 @@ static gboolean file_flush(gpointer handle) ret=fsync(fd); if (ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fsync of handle %p error: %s", __func__, handle, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fsync of handle %p error: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -669,12 +1260,12 @@ static gboolean file_flush(gpointer handle) } static guint32 file_seek(gpointer handle, gint32 movedistance, - gint32 *highmovedistance, WapiSeekMethod method) + gint32 *highmovedistance, gint method) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; gint64 offset, newpos; - int whence, fd; + gint whence, fd; guint32 ret; ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, @@ -691,7 +1282,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance, if(!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(INVALID_SET_FILE_POINTER); @@ -708,7 +1299,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance, whence=SEEK_END; break; default: - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: invalid seek type %d", __func__, method); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: invalid seek type %d", __func__, method); SetLastError (ERROR_INVALID_PARAMETER); return(INVALID_SET_FILE_POINTER); @@ -717,18 +1308,18 @@ static guint32 file_seek(gpointer handle, gint32 movedistance, #ifdef HAVE_LARGE_FILE_SUPPORT if(highmovedistance==NULL) { offset=movedistance; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting offset to %lld (low %d)", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting offset to %lld (low %d)", __func__, offset, movedistance); } else { offset=((gint64) *highmovedistance << 32) | (guint32)movedistance; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting offset to %lld 0x%llx (high %d 0x%x, low %d 0x%x)", __func__, offset, offset, *highmovedistance, *highmovedistance, movedistance, movedistance); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting offset to %lld 0x%llx (high %d 0x%x, low %d 0x%x)", __func__, offset, offset, *highmovedistance, *highmovedistance, movedistance, movedistance); } #else offset=movedistance; #endif - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: moving handle %p by %lld bytes from %d", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: moving handle %p by %lld bytes from %d", __func__, handle, (long long)offset, whence); #ifdef PLATFORM_ANDROID @@ -738,14 +1329,14 @@ static guint32 file_seek(gpointer handle, gint32 movedistance, newpos=lseek(fd, offset, whence); #endif if(newpos==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lseek on handle %p returned error %s", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lseek on handle %p returned error %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); return(INVALID_SET_FILE_POINTER); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lseek returns %lld", __func__, newpos); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lseek returns %lld", __func__, newpos); #ifdef HAVE_LARGE_FILE_SUPPORT ret=newpos & 0xFFFFFFFF; @@ -760,7 +1351,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance, } #endif - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: move of handle %p returning %d/%d", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: move of handle %p returning %d/%d", __func__, handle, ret, highmovedistance==NULL?0:*highmovedistance); return(ret); @@ -768,11 +1359,11 @@ static guint32 file_seek(gpointer handle, gint32 movedistance, static gboolean file_setendoffile(gpointer handle) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; struct stat statbuf; off_t pos; - int ret, fd; + gint ret, fd; MonoThreadInfo *info = mono_thread_info_current (); ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, @@ -787,7 +1378,7 @@ static gboolean file_setendoffile(gpointer handle) if(!(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); @@ -801,7 +1392,7 @@ static gboolean file_setendoffile(gpointer handle) ret=fstat(fd, &statbuf); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -810,7 +1401,7 @@ static gboolean file_setendoffile(gpointer handle) pos=lseek(fd, (off_t)0, SEEK_CUR); if(pos==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p lseek failed: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p lseek failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -837,7 +1428,7 @@ static gboolean file_setendoffile(gpointer handle) !mono_thread_info_is_interrupt_state (info)); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p extend write failed: %s", __func__, handle, strerror(errno)); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p extend write failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); return(FALSE); @@ -846,7 +1437,7 @@ static gboolean file_setendoffile(gpointer handle) /* And put the file position back after the write */ ret = lseek (fd, pos, SEEK_SET); if (ret == -1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p second lseek failed: %s", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p second lseek failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -865,7 +1456,7 @@ static gboolean file_setendoffile(gpointer handle) } while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info)); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p ftruncate failed: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p ftruncate failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -878,12 +1469,12 @@ static gboolean file_setendoffile(gpointer handle) static guint32 file_getfilesize(gpointer handle, guint32 *highsize) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; struct stat statbuf; guint32 size; - int ret; - int fd; + gint ret; + gint fd; ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle); @@ -898,7 +1489,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize) if(!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(INVALID_FILE_SIZE); @@ -912,7 +1503,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize) ret = fstat(fd, &statbuf); if (ret == -1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -924,7 +1515,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize) if (S_ISBLK(statbuf.st_mode)) { guint64 bigsize; if (ioctl(fd, BLKGETSIZE64, &bigsize) < 0) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p ioctl BLKGETSIZE64 failed: %s", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p ioctl BLKGETSIZE64 failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -936,7 +1527,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize) *highsize = bigsize>>32; } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning block device size %d/%d", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning block device size %d/%d", __func__, size, *highsize); return(size); @@ -956,20 +1547,20 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize) size = statbuf.st_size; #endif - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning size %d/%d", __func__, size, *highsize); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning size %d/%d", __func__, size, *highsize); return(size); } -static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time, - WapiFileTime *last_access, - WapiFileTime *last_write) +static gboolean file_getfiletime(gpointer handle, FILETIME *create_time, + FILETIME *access_time, + FILETIME *write_time) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; struct stat statbuf; guint64 create_ticks, access_ticks, write_ticks; - int ret, fd; + gint ret, fd; ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle); @@ -983,7 +1574,7 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time, if(!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); @@ -992,14 +1583,14 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time, ret=fstat(fd, &statbuf); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); return(FALSE); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: atime: %ld ctime: %ld mtime: %ld", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: atime: %ld ctime: %ld mtime: %ld", __func__, statbuf.st_atime, statbuf.st_ctime, statbuf.st_mtime); @@ -1020,7 +1611,7 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time, access_ticks=((guint64)statbuf.st_atime*10000000)+116444736000000000ULL; write_ticks=((guint64)statbuf.st_mtime*10000000)+116444736000000000ULL; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: aticks: %llu cticks: %llu wticks: %llu", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: aticks: %llu cticks: %llu wticks: %llu", __func__, access_ticks, create_ticks, write_ticks); if(create_time!=NULL) { @@ -1028,30 +1619,30 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time, create_time->dwHighDateTime = create_ticks >> 32; } - if(last_access!=NULL) { - last_access->dwLowDateTime = access_ticks & 0xFFFFFFFF; - last_access->dwHighDateTime = access_ticks >> 32; + if(access_time!=NULL) { + access_time->dwLowDateTime = access_ticks & 0xFFFFFFFF; + access_time->dwHighDateTime = access_ticks >> 32; } - if(last_write!=NULL) { - last_write->dwLowDateTime = write_ticks & 0xFFFFFFFF; - last_write->dwHighDateTime = write_ticks >> 32; + if(write_time!=NULL) { + write_time->dwLowDateTime = write_ticks & 0xFFFFFFFF; + write_time->dwHighDateTime = write_ticks >> 32; } return(TRUE); } static gboolean file_setfiletime(gpointer handle, - const WapiFileTime *create_time G_GNUC_UNUSED, - const WapiFileTime *last_access, - const WapiFileTime *last_write) + const FILETIME *create_time G_GNUC_UNUSED, + const FILETIME *access_time, + const FILETIME *write_time) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gboolean ok; struct utimbuf utbuf; struct stat statbuf; guint64 access_ticks, write_ticks; - int ret, fd; + gint ret, fd; ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle); @@ -1065,14 +1656,14 @@ static gboolean file_setfiletime(gpointer handle, if(!(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); } if(file_handle->filename == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p unknown filename", __func__, handle); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p unknown filename", __func__, handle); SetLastError (ERROR_INVALID_HANDLE); return(FALSE); @@ -1083,28 +1674,28 @@ static gboolean file_setfiletime(gpointer handle, */ ret=fstat (fd, &statbuf); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle, strerror(errno)); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); } - if(last_access!=NULL) { - access_ticks=((guint64)last_access->dwHighDateTime << 32) + - last_access->dwLowDateTime; + if(access_time!=NULL) { + access_ticks=((guint64)access_time->dwHighDateTime << 32) + + access_time->dwLowDateTime; /* This is (time_t)0. We can actually go to INT_MIN, * but this will do for now. */ if (access_ticks < 116444736000000000ULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set access time too early", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set access time too early", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); } if (sizeof (utbuf.actime) == 4 && ((access_ticks - 116444736000000000ULL) / 10000000) > INT_MAX) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time that is too big for a 32bits time_t", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time that is too big for a 32bits time_t", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); @@ -1115,20 +1706,20 @@ static gboolean file_setfiletime(gpointer handle, utbuf.actime=statbuf.st_atime; } - if(last_write!=NULL) { - write_ticks=((guint64)last_write->dwHighDateTime << 32) + - last_write->dwLowDateTime; + if(write_time!=NULL) { + write_ticks=((guint64)write_time->dwHighDateTime << 32) + + write_time->dwLowDateTime; /* This is (time_t)0. We can actually go to INT_MIN, * but this will do for now. */ if (write_ticks < 116444736000000000ULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time too early", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time too early", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); } if (sizeof (utbuf.modtime) == 4 && ((write_ticks - 116444736000000000ULL) / 10000000) > INT_MAX) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time that is too big for a 32bits time_t", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time that is too big for a 32bits time_t", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); @@ -1139,12 +1730,12 @@ static gboolean file_setfiletime(gpointer handle, utbuf.modtime=statbuf.st_mtime; } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting handle %p access %ld write %ld", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting handle %p access %ld write %ld", __func__, handle, utbuf.actime, utbuf.modtime); ret = _wapi_utime (file_handle->filename, &utbuf); if (ret == -1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p [%s] utime failed: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p [%s] utime failed: %s", __func__, handle, file_handle->filename, strerror(errno)); SetLastError (ERROR_INVALID_PARAMETER); @@ -1156,16 +1747,16 @@ static gboolean file_setfiletime(gpointer handle, static void console_close (gpointer handle, gpointer data) { - struct _WapiHandle_file *console_handle = (struct _WapiHandle_file *)data; - int fd = console_handle->fd; + MonoW32HandleFile *console_handle = (MonoW32HandleFile *)data; + gint fd = console_handle->fd; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing console handle %p", __func__, handle); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing console handle %p", __func__, handle); g_free (console_handle->filename); if (fd > 2) { if (console_handle->share_info) - _wapi_handle_share_release (console_handle->share_info); + file_share_release (console_handle->share_info); close (fd); } } @@ -1182,21 +1773,20 @@ static const gchar* console_typename (void) static gsize console_typesize (void) { - return sizeof (struct _WapiHandle_file); + return sizeof (MonoW32HandleFile); } -static WapiFileType console_getfiletype(void) +static gint console_getfiletype(void) { return(FILE_TYPE_CHAR); } -static gboolean console_read(gpointer handle, gpointer buffer, - guint32 numbytes, guint32 *bytesread, - WapiOverlapped *overlapped G_GNUC_UNUSED) +static gboolean +console_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread) { - struct _WapiHandle_file *console_handle; + MonoW32HandleFile *console_handle; gboolean ok; - int ret, fd; + gint ret, fd; MonoThreadInfo *info = mono_thread_info_current (); ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_CONSOLE, @@ -1215,7 +1805,7 @@ static gboolean console_read(gpointer handle, gpointer buffer, if(!(console_handle->fileaccess & GENERIC_READ) && !(console_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", __func__, handle, console_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); @@ -1227,7 +1817,7 @@ static gboolean console_read(gpointer handle, gpointer buffer, } while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info)); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, handle, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, handle, strerror(errno)); _wapi_set_last_error_from_errno (); @@ -1241,13 +1831,12 @@ static gboolean console_read(gpointer handle, gpointer buffer, return(TRUE); } -static gboolean console_write(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped G_GNUC_UNUSED) +static gboolean +console_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten) { - struct _WapiHandle_file *console_handle; + MonoW32HandleFile *console_handle; gboolean ok; - int ret, fd; + gint ret, fd; MonoThreadInfo *info = mono_thread_info_current (); ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_CONSOLE, @@ -1266,7 +1855,7 @@ static gboolean console_write(gpointer handle, gconstpointer buffer, if(!(console_handle->fileaccess & GENERIC_WRITE) && !(console_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, console_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, console_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); @@ -1283,7 +1872,7 @@ static gboolean console_write(gpointer handle, gconstpointer buffer, } else { _wapi_set_last_error_from_errno (); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write of handle %p error: %s", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write of handle %p error: %s", __func__, handle, strerror(errno)); return(FALSE); @@ -1303,20 +1892,20 @@ static const gchar* find_typename (void) static gsize find_typesize (void) { - return sizeof (struct _WapiHandle_find); + return sizeof (MonoW32HandleFind); } static void pipe_close (gpointer handle, gpointer data) { - struct _WapiHandle_file *pipe_handle = (struct _WapiHandle_file*)data; - int fd = pipe_handle->fd; + MonoW32HandleFile *pipe_handle = (MonoW32HandleFile*)data; + gint fd = pipe_handle->fd; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing pipe handle %p fd %d", __func__, handle, fd); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing pipe handle %p fd %d", __func__, handle, fd); /* No filename with pipe handles */ if (pipe_handle->share_info) - _wapi_handle_share_release (pipe_handle->share_info); + file_share_release (pipe_handle->share_info); close (fd); } @@ -1333,21 +1922,20 @@ static const gchar* pipe_typename (void) static gsize pipe_typesize (void) { - return sizeof (struct _WapiHandle_file); + return sizeof (MonoW32HandleFile); } -static WapiFileType pipe_getfiletype(void) +static gint pipe_getfiletype(void) { return(FILE_TYPE_PIPE); } -static gboolean pipe_read (gpointer handle, gpointer buffer, - guint32 numbytes, guint32 *bytesread, - WapiOverlapped *overlapped G_GNUC_UNUSED) +static gboolean +pipe_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread) { - struct _WapiHandle_file *pipe_handle; + MonoW32HandleFile *pipe_handle; gboolean ok; - int ret, fd; + gint ret, fd; MonoThreadInfo *info = mono_thread_info_current (); ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_PIPE, @@ -1366,14 +1954,14 @@ static gboolean pipe_read (gpointer handle, gpointer buffer, if(!(pipe_handle->fileaccess & GENERIC_READ) && !(pipe_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u", __func__, handle, pipe_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: reading up to %d bytes from pipe %p", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: reading up to %d bytes from pipe %p", __func__, numbytes, handle); do { @@ -1386,14 +1974,14 @@ static gboolean pipe_read (gpointer handle, gpointer buffer, } else { _wapi_set_last_error_from_errno (); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__, handle, strerror(errno)); return(FALSE); } } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read %d bytes from pipe %p", __func__, ret, handle); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read %d bytes from pipe %p", __func__, ret, handle); if(bytesread!=NULL) { *bytesread=ret; @@ -1402,13 +1990,12 @@ static gboolean pipe_read (gpointer handle, gpointer buffer, return(TRUE); } -static gboolean pipe_write(gpointer handle, gconstpointer buffer, - guint32 numbytes, guint32 *byteswritten, - WapiOverlapped *overlapped G_GNUC_UNUSED) +static gboolean +pipe_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten) { - struct _WapiHandle_file *pipe_handle; + MonoW32HandleFile *pipe_handle; gboolean ok; - int ret, fd; + gint ret, fd; MonoThreadInfo *info = mono_thread_info_current (); ok=mono_w32handle_lookup (handle, MONO_W32HANDLE_PIPE, @@ -1427,13 +2014,13 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer, if(!(pipe_handle->fileaccess & GENERIC_WRITE) && !(pipe_handle->fileaccess & GENERIC_ALL)) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, pipe_handle->fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, pipe_handle->fileaccess); SetLastError (ERROR_ACCESS_DENIED); return(FALSE); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: writing up to %d bytes to pipe %p", __func__, numbytes, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: writing up to %d bytes to pipe %p", __func__, numbytes, handle); do { @@ -1447,7 +2034,7 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer, } else { _wapi_set_last_error_from_errno (); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write of handle %p error: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write of handle %p error: %s", __func__, handle, strerror(errno)); return(FALSE); @@ -1460,9 +2047,9 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer, return(TRUE); } -static int convert_flags(guint32 fileaccess, guint32 createmode) +static gint convert_flags(guint32 fileaccess, guint32 createmode) { - int flags=0; + gint flags=0; switch(fileaccess) { case GENERIC_READ: @@ -1475,7 +2062,7 @@ static int convert_flags(guint32 fileaccess, guint32 createmode) flags=O_RDWR; break; default: - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unknown access type 0x%x", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unknown access type 0x%x", __func__, fileaccess); break; } @@ -1496,7 +2083,7 @@ static int convert_flags(guint32 fileaccess, guint32 createmode) flags|=O_TRUNC; break; default: - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unknown create mode 0x%x", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unknown create mode 0x%x", __func__, createmode); break; } @@ -1522,12 +2109,12 @@ static mode_t convert_perms(guint32 sharemode) static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode, guint32 fileaccess, - struct _WapiFileShare **share_info) + FileShare **share_info) { gboolean file_already_shared; guint32 file_existing_share, file_existing_access; - file_already_shared = _wapi_handle_get_or_set_share (statbuf->st_dev, statbuf->st_ino, sharemode, fileaccess, &file_existing_share, &file_existing_access, share_info); + file_already_shared = file_share_get (statbuf->st_dev, statbuf->st_ino, sharemode, fileaccess, &file_existing_share, &file_existing_access, share_info); if (file_already_shared) { /* The reference to this share info was incremented @@ -1536,9 +2123,9 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode, */ if (file_existing_share == 0) { /* Quick and easy, no possibility to share */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing = NONE", __func__, fileaccess); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing = NONE", __func__, fileaccess); - _wapi_handle_share_release (*share_info); + file_share_release (*share_info); return(FALSE); } @@ -1548,9 +2135,9 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode, ((file_existing_share == FILE_SHARE_WRITE) && (fileaccess != GENERIC_WRITE))) { /* New access mode doesn't match up */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing: 0x%x", __func__, fileaccess, file_existing_share); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing: 0x%x", __func__, fileaccess, file_existing_share); - _wapi_handle_share_release (*share_info); + file_share_release (*share_info); return(FALSE); } @@ -1560,14 +2147,14 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode, ((file_existing_access & GENERIC_WRITE) && !(sharemode & FILE_SHARE_WRITE))) { /* New share mode doesn't match up */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Access mode prevents open: requested share: 0x%x, file has access: 0x%x", __func__, sharemode, file_existing_access); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Access mode prevents open: requested share: 0x%x, file has access: 0x%x", __func__, sharemode, file_existing_access); - _wapi_handle_share_release (*share_info); + file_share_release (*share_info); return(FALSE); } } else { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: New file!", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: New file!", __func__); } return(TRUE); @@ -1575,12 +2162,12 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode, static gboolean -share_allows_delete (struct stat *statbuf, struct _WapiFileShare **share_info) +share_allows_delete (struct stat *statbuf, FileShare **share_info) { gboolean file_already_shared; guint32 file_existing_share, file_existing_access; - file_already_shared = _wapi_handle_get_or_set_share (statbuf->st_dev, statbuf->st_ino, FILE_SHARE_DELETE, GENERIC_READ, &file_existing_share, &file_existing_access, share_info); + file_already_shared = file_share_get (statbuf->st_dev, statbuf->st_ino, FILE_SHARE_DELETE, GENERIC_READ, &file_existing_share, &file_existing_access, share_info); if (file_already_shared) { /* The reference to this share info was incremented @@ -1589,61 +2176,34 @@ share_allows_delete (struct stat *statbuf, struct _WapiFileShare **share_info) */ if (file_existing_share == 0) { /* Quick and easy, no possibility to share */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing = NONE", __func__, (*share_info)->access); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing = NONE", __func__, (*share_info)->access); - _wapi_handle_share_release (*share_info); + file_share_release (*share_info); return(FALSE); } if (!(file_existing_share & FILE_SHARE_DELETE)) { /* New access mode doesn't match up */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing: 0x%x", __func__, (*share_info)->access, file_existing_share); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Share mode prevents open: requested access: 0x%x, file has sharing: 0x%x", __func__, (*share_info)->access, file_existing_share); - _wapi_handle_share_release (*share_info); + file_share_release (*share_info); return(FALSE); } } else { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: New file!", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: New file!", __func__); } return(TRUE); } -/** - * CreateFile: - * @name: a pointer to a NULL-terminated unicode string, that names - * the file or other object to create. - * @fileaccess: specifies the file access mode - * @sharemode: whether the file should be shared. This parameter is - * currently ignored. - * @security: Ignored for now. - * @createmode: specifies whether to create a new file, whether to - * overwrite an existing file, whether to truncate the file, etc. - * @attrs: specifies file attributes and flags. On win32 attributes - * are characteristics of the file, not the handle, and are ignored - * when an existing file is opened. Flags give the library hints on - * how to process a file to optimise performance. - * @template: the handle of an open %GENERIC_READ file that specifies - * attributes to apply to a newly created file, ignoring @attrs. - * Normally this parameter is NULL. This parameter is ignored when an - * existing file is opened. - * - * Creates a new file handle. This only applies to normal files: - * pipes are handled by CreatePipe(), and console handles are created - * with GetStdHandle(). - * - * Return value: the new handle, or %INVALID_HANDLE_VALUE on error. - */ -gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, - guint32 sharemode, WapiSecurityAttributes *security, - guint32 createmode, guint32 attrs, - gpointer template_ G_GNUC_UNUSED) +gpointer +mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs) { - struct _WapiHandle_file file_handle = {0}; + MonoW32HandleFile file_handle = {0}; gpointer handle; - int flags=convert_flags(fileaccess, createmode); + gint flags=convert_flags(fileaccess, createmode); /*mode_t perms=convert_perms(sharemode);*/ /* we don't use sharemode, because that relates to sharing of * the file when the file is open and is already handled by @@ -1652,7 +2212,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, */ mode_t perms=0666; gchar *filename; - int fd, ret; + gint fd, ret; MonoW32HandleType handle_type; struct stat statbuf; @@ -1665,7 +2225,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, } if (name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(INVALID_HANDLE_VALUE); @@ -1673,13 +2233,13 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, filename = mono_unicode_to_external (name); if (filename == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(INVALID_HANDLE_VALUE); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Opening %s with share 0x%x and access 0x%x", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Opening %s with share 0x%x and access 0x%x", __func__, filename, sharemode, fileaccess); fd = _wapi_open (filename, flags, perms); @@ -1687,7 +2247,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, /* If we were trying to open a directory with write permissions * (e.g. O_WRONLY or O_RDWR), this call will fail with * EISDIR. However, this is a bit bogus because calls to - * manipulate the directory (e.g. SetFileTime) will still work on + * manipulate the directory (e.g. mono_w32file_set_times) will still work on * the directory because they use other API calls * (e.g. utime()). Hence, if we failed with the EISDIR error, try * to open the directory again without write permission. @@ -1699,7 +2259,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, } if (fd == -1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error opening file %s: %s", __func__, filename, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error opening file %s: %s", __func__, filename, strerror(errno)); _wapi_set_last_path_error_from_errno (NULL, filename); g_free (filename); @@ -1708,7 +2268,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, } if (fd >= mono_w32handle_fd_reserve) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__); SetLastError (ERROR_TOO_MANY_OPEN_FILES); @@ -1720,7 +2280,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, ret = fstat (fd, &statbuf); if (ret == -1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fstat error of file %s: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fstat error of file %s: %s", __func__, filename, strerror (errno)); _wapi_set_last_error_from_errno (); g_free (filename); @@ -1746,7 +2306,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, } if (file_handle.share_info == NULL) { /* No space, so no more files can be opened */ - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: No space in the share table", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: No space in the share table", __func__); SetLastError (ERROR_TOO_MANY_OPEN_FILES); close (fd); @@ -1756,11 +2316,6 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, } file_handle.filename = filename; - - if(security!=NULL) { - //file_handle->security_attributes=_wapi_handle_scratch_store ( - //security, sizeof(WapiSecurityAttributes)); - } file_handle.fd = fd; file_handle.fileaccess=fileaccess; @@ -1804,33 +2359,24 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess, return(INVALID_HANDLE_VALUE); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning handle %p", __func__, handle); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning handle %p", __func__, handle); return(handle); } -/** - * DeleteFile: - * @name: a pointer to a NULL-terminated unicode string, that names - * the file to be deleted. - * - * Deletes file @name. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean DeleteFile(const gunichar2 *name) +gboolean mono_w32file_delete(const gunichar2 *name) { gchar *filename; - int retval; + gint retval; gboolean ret = FALSE; guint32 attrs; #if 0 struct stat statbuf; - struct _WapiFileShare *shareinfo; + FileShare *shareinfo; #endif if(name==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -1838,16 +2384,16 @@ gboolean DeleteFile(const gunichar2 *name) filename=mono_unicode_to_external(name); if(filename==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); } - attrs = GetFileAttributes (name); + attrs = mono_w32file_get_attributes (name); if (attrs == INVALID_FILE_ATTRIBUTES) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file attributes error", __func__); - /* Error set by GetFileAttributes() */ + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file attributes error", __func__); + /* Error set by mono_w32file_get_attributes() */ g_free (filename); return(FALSE); } @@ -1873,7 +2419,7 @@ gboolean DeleteFile(const gunichar2 *name) return FALSE; } if (shareinfo) - _wapi_handle_share_release (shareinfo); + file_share_release (shareinfo); #endif retval = _wapi_unlink (filename); @@ -1889,29 +2435,17 @@ gboolean DeleteFile(const gunichar2 *name) return(ret); } -/** - * MoveFile: - * @name: a pointer to a NULL-terminated unicode string, that names - * the file to be moved. - * @dest_name: a pointer to a NULL-terminated unicode string, that is the - * new name for the file. - * - * Renames file @name to @dest_name. - * MoveFile sets ERROR_ALREADY_EXISTS if the destination exists, except - * when it is the same file as the source. In that case it silently succeeds. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name) +static gboolean +MoveFile (gunichar2 *name, gunichar2 *dest_name) { gchar *utf8_name, *utf8_dest_name; - int result, errno_copy; + gint result, errno_copy; struct stat stat_src, stat_dest; gboolean ret = FALSE; - struct _WapiFileShare *shareinfo; + FileShare *shareinfo; if(name==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -1919,14 +2453,14 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name) utf8_name = mono_unicode_to_external (name); if (utf8_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return FALSE; } if(dest_name==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); g_free (utf8_name); SetLastError (ERROR_INVALID_NAME); @@ -1935,7 +2469,7 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name) utf8_dest_name = mono_unicode_to_external (dest_name); if (utf8_dest_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); g_free (utf8_name); SetLastError (ERROR_INVALID_NAME); @@ -1978,7 +2512,7 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name) return FALSE; } if (shareinfo) - _wapi_handle_share_release (shareinfo); + file_share_release (shareinfo); result = _wapi_rename (utf8_name, utf8_dest_name); errno_copy = errno; @@ -2007,17 +2541,19 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name) g_free (utf8_dest_name); if (result != 0 && errno_copy == EXDEV) { + gint32 copy_error; + if (S_ISDIR (stat_src.st_mode)) { SetLastError (ERROR_NOT_SAME_DEVICE); return FALSE; } /* Try a copy to the new location, and delete the source */ - if (CopyFile (name, dest_name, TRUE)==FALSE) { - /* CopyFile will set the error */ + if (!mono_w32file_copy (name, dest_name, FALSE, ©_error)) { + /* mono_w32file_copy will set the error */ return(FALSE); } - return(DeleteFile (name)); + return(mono_w32file_delete (name)); } if (result == 0) { @@ -2028,15 +2564,15 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name) } static gboolean -write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors) +write_file (gint src_fd, gint dest_fd, struct stat *st_src, gboolean report_errors) { - int remain, n; - char *buf, *wbuf; - int buf_size = st_src->st_blksize; + gint remain, n; + gchar *buf, *wbuf; + gint buf_size = st_src->st_blksize; MonoThreadInfo *info = mono_thread_info_current (); buf_size = buf_size < 8192 ? 8192 : (buf_size > 65536 ? 65536 : buf_size); - buf = (char *) g_malloc (buf_size); + buf = (gchar *) g_malloc (buf_size); for (;;) { remain = read (src_fd, buf, buf_size); @@ -2062,7 +2598,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors if (report_errors) _wapi_set_last_error_from_errno (); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write failed.", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write failed.", __func__); g_free (buf); return FALSE; } @@ -2076,30 +2612,18 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors return TRUE ; } -/** - * CopyFile: - * @name: a pointer to a NULL-terminated unicode string, that names - * the file to be copied. - * @dest_name: a pointer to a NULL-terminated unicode string, that is the - * new name for the file. - * @fail_if_exists: if TRUE and dest_name exists, the copy will fail. - * - * Copies file @name to @dest_name - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, - gboolean fail_if_exists) +static gboolean +CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_exists) { gchar *utf8_src, *utf8_dest; - int src_fd, dest_fd; + gint src_fd, dest_fd; struct stat st, dest_st; struct utimbuf dest_time; gboolean ret = TRUE; - int ret_utime; + gint ret_utime; if(name==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -2107,7 +2631,7 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, utf8_src = mono_unicode_to_external (name); if (utf8_src == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of source returned NULL", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of source returned NULL", __func__); SetLastError (ERROR_INVALID_PARAMETER); @@ -2115,7 +2639,7 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, } if(dest_name==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: dest is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: dest is NULL", __func__); g_free (utf8_src); SetLastError (ERROR_INVALID_NAME); @@ -2124,7 +2648,7 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, utf8_dest = mono_unicode_to_external (dest_name); if (utf8_dest == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of dest returned NULL", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of dest returned NULL", __func__); SetLastError (ERROR_INVALID_PARAMETER); @@ -2205,7 +2729,7 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, dest_time.actime = st.st_atime; ret_utime = utime (utf8_dest, &dest_time); if (ret_utime == -1) - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file [%s] utime failed: %s", __func__, utf8_dest, strerror(errno)); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file [%s] utime failed: %s", __func__, utf8_dest, strerror(errno)); g_free (utf8_src); g_free (utf8_dest); @@ -2219,14 +2743,14 @@ convert_arg_to_utf8 (const gunichar2 *arg, const gchar *arg_name) gchar *utf8_ret; if (arg == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s is NULL", __func__, arg_name); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s is NULL", __func__, arg_name); SetLastError (ERROR_INVALID_NAME); return NULL; } utf8_ret = mono_unicode_to_external (arg); if (utf8_ret == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of %s returned NULL", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of %s returned NULL", __func__, arg_name); SetLastError (ERROR_INVALID_PARAMETER); return NULL; @@ -2235,12 +2759,10 @@ convert_arg_to_utf8 (const gunichar2 *arg, const gchar *arg_name) return utf8_ret; } -gboolean -ReplaceFile (const gunichar2 *replacedFileName, const gunichar2 *replacementFileName, - const gunichar2 *backupFileName, guint32 replaceFlags, - gpointer exclude, gpointer reserved) +static gboolean +ReplaceFile (const gunichar2 *replacedFileName, const gunichar2 *replacementFileName, const gunichar2 *backupFileName, guint32 replaceFlags, gpointer exclude, gpointer reserved) { - int result, backup_fd = -1,replaced_fd = -1; + gint result, backup_fd = -1,replaced_fd = -1; gchar *utf8_replacedFileName, *utf8_replacementFileName = NULL, *utf8_backupFileName = NULL; struct stat stBackup; gboolean ret = FALSE; @@ -2262,53 +2784,124 @@ ReplaceFile (const gunichar2 *replacedFileName, const gunichar2 *replacementFile goto replace_cleanup; } - result = _wapi_rename (utf8_replacementFileName, utf8_replacedFileName); - if (result == -1) { - _wapi_set_last_path_error_from_errno (NULL, utf8_replacementFileName); - _wapi_rename (utf8_backupFileName, utf8_replacedFileName); - if (backup_fd != -1 && !fstat (backup_fd, &stBackup)) { - replaced_fd = _wapi_open (utf8_backupFileName, O_WRONLY | O_CREAT | O_TRUNC, - stBackup.st_mode); - - if (replaced_fd == -1) - goto replace_cleanup; + result = _wapi_rename (utf8_replacementFileName, utf8_replacedFileName); + if (result == -1) { + _wapi_set_last_path_error_from_errno (NULL, utf8_replacementFileName); + _wapi_rename (utf8_backupFileName, utf8_replacedFileName); + if (backup_fd != -1 && !fstat (backup_fd, &stBackup)) { + replaced_fd = _wapi_open (utf8_backupFileName, O_WRONLY | O_CREAT | O_TRUNC, + stBackup.st_mode); + + if (replaced_fd == -1) + goto replace_cleanup; + + write_file (backup_fd, replaced_fd, &stBackup, FALSE); + } + + goto replace_cleanup; + } + + ret = TRUE; + +replace_cleanup: + g_free (utf8_replacedFileName); + g_free (utf8_replacementFileName); + g_free (utf8_backupFileName); + if (backup_fd != -1) + close (backup_fd); + if (replaced_fd != -1) + close (replaced_fd); + return ret; +} + +static mono_mutex_t stdhandle_mutex; + +static gpointer +_wapi_stdhandle_create (gint fd, const gchar *name) +{ + gpointer handle; + gint flags; + MonoW32HandleFile file_handle = {0}; + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating standard handle type %s, fd %d", __func__, name, fd); + +#if !defined(__native_client__) + /* Check if fd is valid */ + do { + flags = fcntl(fd, F_GETFL); + } while (flags == -1 && errno == EINTR); + + if (flags == -1) { + /* Invalid fd. Not really much point checking for EBADF + * specifically + */ + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl error on fd %d: %s", __func__, fd, strerror(errno)); + + SetLastError (_wapi_get_win32_file_error (errno)); + return INVALID_HANDLE_VALUE; + } + + switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) { + case O_RDONLY: + file_handle.fileaccess = GENERIC_READ; + break; + case O_WRONLY: + file_handle.fileaccess = GENERIC_WRITE; + break; + case O_RDWR: + file_handle.fileaccess = GENERIC_READ | GENERIC_WRITE; + break; + default: + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't figure out flags 0x%x", __func__, flags); + file_handle.fileaccess = 0; + break; + } +#else + /* + * fcntl will return -1 in nacl, as there is no real file system API. + * Yet, standard streams are available. + */ + file_handle.fileaccess = (fd == STDIN_FILENO) ? GENERIC_READ : GENERIC_WRITE; +#endif + + file_handle.fd = fd; + file_handle.filename = g_strdup(name); + /* some default security attributes might be needed */ + file_handle.security_attributes = 0; - write_file (backup_fd, replaced_fd, &stBackup, FALSE); - } + /* Apparently input handles can't be written to. (I don't + * know if output or error handles can't be read from.) + */ + if (fd == 0) + file_handle.fileaccess &= ~GENERIC_WRITE; - goto replace_cleanup; + file_handle.sharemode = 0; + file_handle.attrs = 0; + + handle = mono_w32handle_new_fd (MONO_W32HANDLE_CONSOLE, fd, &file_handle); + if (handle == INVALID_HANDLE_VALUE) { + g_warning ("%s: error creating file handle", __func__); + SetLastError (ERROR_GEN_FAILURE); + return INVALID_HANDLE_VALUE; } - ret = TRUE; + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning handle %p", __func__, handle); -replace_cleanup: - g_free (utf8_replacedFileName); - g_free (utf8_replacementFileName); - g_free (utf8_backupFileName); - if (backup_fd != -1) - close (backup_fd); - if (replaced_fd != -1) - close (replaced_fd); - return ret; + return handle; } -/** - * GetStdHandle: - * @stdhandle: specifies the file descriptor - * - * Returns a handle for stdin, stdout, or stderr. Always returns the - * same handle for the same @stdhandle. - * - * Return value: the handle, or %INVALID_HANDLE_VALUE on error - */ - -static mono_mutex_t stdhandle_mutex; +enum { + STD_INPUT_HANDLE = -10, + STD_OUTPUT_HANDLE = -11, + STD_ERROR_HANDLE = -12, +}; -gpointer GetStdHandle(WapiStdHandle stdhandle) +static gpointer +mono_w32file_get_std_handle (gint stdhandle) { - struct _WapiHandle_file *file_handle; + MonoW32HandleFile *file_handle; gpointer handle; - int fd; + gint fd; const gchar *name; gboolean ok; @@ -2329,10 +2922,7 @@ gpointer GetStdHandle(WapiStdHandle stdhandle) break; default: - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unknown standard handle type", __func__); - - SetLastError (ERROR_INVALID_PARAMETER); - return(INVALID_HANDLE_VALUE); + g_assert_not_reached (); } handle = GINT_TO_POINTER (fd); @@ -2360,35 +2950,8 @@ gpointer GetStdHandle(WapiStdHandle stdhandle) return(handle); } -/** - * ReadFile: - * @handle: The file handle to read from. The handle must have - * %GENERIC_READ access. - * @buffer: The buffer to store read data in - * @numbytes: The maximum number of bytes to read - * @bytesread: The actual number of bytes read is stored here. This - * value can be zero if the handle is positioned at the end of the - * file. - * @overlapped: points to a required %WapiOverlapped structure if - * @handle has the %FILE_FLAG_OVERLAPPED option set, should be NULL - * otherwise. - * - * If @handle does not have the %FILE_FLAG_OVERLAPPED option set, this - * function reads up to @numbytes bytes from the file from the current - * file position, and stores them in @buffer. If there are not enough - * bytes left in the file, just the amount available will be read. - * The actual number of bytes read is stored in @bytesread. - - * If @handle has the %FILE_FLAG_OVERLAPPED option set, the current - * file position is ignored and the read position is taken from data - * in the @overlapped structure. - * - * Return value: %TRUE if the read succeeds (even if no bytes were - * read due to an attempt to read past the end of the file), %FALSE on - * error. - */ -gboolean ReadFile(gpointer handle, gpointer buffer, guint32 numbytes, - guint32 *bytesread, WapiOverlapped *overlapped) +gboolean +mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread) { MonoW32HandleType type; @@ -2399,37 +2962,11 @@ gboolean ReadFile(gpointer handle, gpointer buffer, guint32 numbytes, return(FALSE); } - return(io_ops[type].readfile (handle, buffer, numbytes, bytesread, - overlapped)); + return(io_ops[type].readfile (handle, buffer, numbytes, bytesread)); } -/** - * WriteFile: - * @handle: The file handle to write to. The handle must have - * %GENERIC_WRITE access. - * @buffer: The buffer to read data from. - * @numbytes: The maximum number of bytes to write. - * @byteswritten: The actual number of bytes written is stored here. - * If the handle is positioned at the file end, the length of the file - * is extended. This parameter may be %NULL. - * @overlapped: points to a required %WapiOverlapped structure if - * @handle has the %FILE_FLAG_OVERLAPPED option set, should be NULL - * otherwise. - * - * If @handle does not have the %FILE_FLAG_OVERLAPPED option set, this - * function writes up to @numbytes bytes from @buffer to the file at - * the current file position. If @handle is positioned at the end of - * the file, the file is extended. The actual number of bytes written - * is stored in @byteswritten. - * - * If @handle has the %FILE_FLAG_OVERLAPPED option set, the current - * file position is ignored and the write position is taken from data - * in the @overlapped structure. - * - * Return value: %TRUE if the write succeeds, %FALSE on error. - */ -gboolean WriteFile(gpointer handle, gconstpointer buffer, guint32 numbytes, - guint32 *byteswritten, WapiOverlapped *overlapped) +gboolean +mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten) { MonoW32HandleType type; @@ -2440,21 +2977,11 @@ gboolean WriteFile(gpointer handle, gconstpointer buffer, guint32 numbytes, return(FALSE); } - return(io_ops[type].writefile (handle, buffer, numbytes, byteswritten, - overlapped)); + return(io_ops[type].writefile (handle, buffer, numbytes, byteswritten)); } -/** - * FlushFileBuffers: - * @handle: Handle to open file. The handle must have - * %GENERIC_WRITE access. - * - * Flushes buffers of the file and causes all unwritten data to - * be written. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean FlushFileBuffers(gpointer handle) +gboolean +mono_w32file_flush (gpointer handle) { MonoW32HandleType type; @@ -2468,17 +2995,8 @@ gboolean FlushFileBuffers(gpointer handle) return(io_ops[type].flushfile (handle)); } -/** - * SetEndOfFile: - * @handle: The file handle to set. The handle must have - * %GENERIC_WRITE access. - * - * Moves the end-of-file position to the current position of the file - * pointer. This function is used to truncate or extend a file. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean SetEndOfFile(gpointer handle) +gboolean +mono_w32file_truncate (gpointer handle) { MonoW32HandleType type; @@ -2492,37 +3010,8 @@ gboolean SetEndOfFile(gpointer handle) return(io_ops[type].setendoffile (handle)); } -/** - * SetFilePointer: - * @handle: The file handle to set. The handle must have - * %GENERIC_READ or %GENERIC_WRITE access. - * @movedistance: Low 32 bits of a signed value that specifies the - * number of bytes to move the file pointer. - * @highmovedistance: Pointer to the high 32 bits of a signed value - * that specifies the number of bytes to move the file pointer, or - * %NULL. - * @method: The starting point for the file pointer move. - * - * Sets the file pointer of an open file. - * - * The distance to move the file pointer is calculated from - * @movedistance and @highmovedistance: If @highmovedistance is %NULL, - * @movedistance is the 32-bit signed value; otherwise, @movedistance - * is the low 32 bits and @highmovedistance a pointer to the high 32 - * bits of a 64 bit signed value. A positive distance moves the file - * pointer forward from the position specified by @method; a negative - * distance moves the file pointer backward. - * - * If the library is compiled without large file support, - * @highmovedistance is ignored and its value is set to zero on a - * successful return. - * - * Return value: On success, the low 32 bits of the new file pointer. - * If @highmovedistance is not %NULL, the high 32 bits of the new file - * pointer are stored there. On failure, %INVALID_SET_FILE_POINTER. - */ -guint32 SetFilePointer(gpointer handle, gint32 movedistance, - gint32 *highmovedistance, WapiSeekMethod method) +guint32 +mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method) { MonoW32HandleType type; @@ -2537,18 +3026,8 @@ guint32 SetFilePointer(gpointer handle, gint32 movedistance, method)); } -/** - * GetFileType: - * @handle: The file handle to test. - * - * Finds the type of file @handle. - * - * Return value: %FILE_TYPE_UNKNOWN - the type of the file @handle is - * unknown. %FILE_TYPE_DISK - @handle is a disk file. - * %FILE_TYPE_CHAR - @handle is a character device, such as a console. - * %FILE_TYPE_PIPE - @handle is a named or anonymous pipe. - */ -WapiFileType GetFileType(gpointer handle) +gint +mono_w32file_get_type(gpointer handle) { MonoW32HandleType type; @@ -2562,23 +3041,8 @@ WapiFileType GetFileType(gpointer handle) return(io_ops[type].getfiletype ()); } -/** - * GetFileSize: - * @handle: The file handle to query. The handle must have - * %GENERIC_READ or %GENERIC_WRITE access. - * @highsize: If non-%NULL, the high 32 bits of the file size are - * stored here. - * - * Retrieves the size of the file @handle. - * - * If the library is compiled without large file support, @highsize - * has its value set to zero on a successful return. - * - * Return value: On success, the low 32 bits of the file size. If - * @highsize is non-%NULL then the high 32 bits of the file size are - * stored here. On failure %INVALID_FILE_SIZE is returned. - */ -guint32 GetFileSize(gpointer handle, guint32 *highsize) +static guint32 +GetFileSize(gpointer handle, guint32 *highsize) { MonoW32HandleType type; @@ -2592,33 +3056,8 @@ guint32 GetFileSize(gpointer handle, guint32 *highsize) return(io_ops[type].getfilesize (handle, highsize)); } -/** - * GetFileTime: - * @handle: The file handle to query. The handle must have - * %GENERIC_READ access. - * @create_time: Points to a %WapiFileTime structure to receive the - * number of ticks since the epoch that file was created. May be - * %NULL. - * @last_access: Points to a %WapiFileTime structure to receive the - * number of ticks since the epoch when file was last accessed. May be - * %NULL. - * @last_write: Points to a %WapiFileTime structure to receive the - * number of ticks since the epoch when file was last written to. May - * be %NULL. - * - * Finds the number of ticks since the epoch that the file referenced - * by @handle was created, last accessed and last modified. A tick is - * a 100 nanosecond interval. The epoch is Midnight, January 1 1601 - * GMT. - * - * Create time isn't recorded on POSIX file systems or reported by - * stat(2), so that time is guessed by returning the oldest of the - * other times. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean GetFileTime(gpointer handle, WapiFileTime *create_time, - WapiFileTime *last_access, WapiFileTime *last_write) +gboolean +mono_w32file_get_times(gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time) { MonoW32HandleType type; @@ -2629,36 +3068,12 @@ gboolean GetFileTime(gpointer handle, WapiFileTime *create_time, return(FALSE); } - return(io_ops[type].getfiletime (handle, create_time, last_access, - last_write)); + return(io_ops[type].getfiletime (handle, create_time, access_time, + write_time)); } -/** - * SetFileTime: - * @handle: The file handle to set. The handle must have - * %GENERIC_WRITE access. - * @create_time: Points to a %WapiFileTime structure that contains the - * number of ticks since the epoch that the file was created. May be - * %NULL. - * @last_access: Points to a %WapiFileTime structure that contains the - * number of ticks since the epoch when the file was last accessed. - * May be %NULL. - * @last_write: Points to a %WapiFileTime structure that contains the - * number of ticks since the epoch when the file was last written to. - * May be %NULL. - * - * Sets the number of ticks since the epoch that the file referenced - * by @handle was created, last accessed or last modified. A tick is - * a 100 nanosecond interval. The epoch is Midnight, January 1 1601 - * GMT. - * - * Create time isn't recorded on POSIX file systems, and is ignored. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean SetFileTime(gpointer handle, const WapiFileTime *create_time, - const WapiFileTime *last_access, - const WapiFileTime *last_write) +gboolean +mono_w32file_set_times(gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time) { MonoW32HandleType type; @@ -2669,8 +3084,8 @@ gboolean SetFileTime(gpointer handle, const WapiFileTime *create_time, return(FALSE); } - return(io_ops[type].setfiletime (handle, create_time, last_access, - last_write)); + return(io_ops[type].setfiletime (handle, create_time, access_time, + write_time)); } /* A tick is a 100-nanosecond interval. File time epoch is Midnight, @@ -2690,25 +3105,14 @@ static const guint16 mon_yday[2][13]={ {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}, }; -/** - * FileTimeToSystemTime: - * @file_time: Points to a %WapiFileTime structure that contains the - * number of ticks to convert. - * @system_time: Points to a %WapiSystemTime structure to receive the - * broken-out time. - * - * Converts a tick count into broken-out time values. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean FileTimeToSystemTime(const WapiFileTime *file_time, - WapiSystemTime *system_time) +gboolean +mono_w32file_filetime_to_systemtime(const FILETIME *file_time, SYSTEMTIME *system_time) { gint64 file_ticks, totaldays, rem, y; const guint16 *ip; if(system_time==NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: system_time NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: system_time NULL", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); @@ -2722,7 +3126,7 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time, * year and day calculation to work later */ if(file_ticks<0) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file_time too big", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file_time too big", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(FALSE); @@ -2730,29 +3134,29 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time, totaldays=(file_ticks / TICKS_PER_DAY); rem = file_ticks % TICKS_PER_DAY; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld rem: %lld", __func__, totaldays, rem); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld rem: %lld", __func__, totaldays, rem); system_time->wHour=rem/TICKS_PER_HOUR; rem %= TICKS_PER_HOUR; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Hour: %d rem: %lld", __func__, system_time->wHour, rem); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Hour: %d rem: %lld", __func__, system_time->wHour, rem); system_time->wMinute = rem / TICKS_PER_MINUTE; rem %= TICKS_PER_MINUTE; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Minute: %d rem: %lld", __func__, system_time->wMinute, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Minute: %d rem: %lld", __func__, system_time->wMinute, rem); system_time->wSecond = rem / TICKS_PER_SECOND; rem %= TICKS_PER_SECOND; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Second: %d rem: %lld", __func__, system_time->wSecond, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Second: %d rem: %lld", __func__, system_time->wSecond, rem); system_time->wMilliseconds = rem / TICKS_PER_MILLISECOND; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Milliseconds: %d", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Milliseconds: %d", __func__, system_time->wMilliseconds); /* January 1, 1601 was a Monday, according to Emacs calendar */ system_time->wDayOfWeek = ((1 + totaldays) % 7) + 1; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Day of week: %d", __func__, system_time->wDayOfWeek); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Day of week: %d", __func__, system_time->wDayOfWeek); /* This algorithm to find year and month given days from epoch * from glibc @@ -2765,7 +3169,7 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time, while(totaldays < 0 || totaldays >= (isleap(y)?366:365)) { /* Guess a corrected year, assuming 365 days per year */ gint64 yg = y + totaldays / 365 - (totaldays % 365 < 0); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld yg: %lld y: %lld", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld yg: %lld y: %lld", __func__, totaldays, yg, y); g_message("%s: LEAPS(yg): %lld LEAPS(y): %lld", __func__, @@ -2775,13 +3179,13 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time, totaldays -= ((yg - y) * 365 + LEAPS_THRU_END_OF (yg - 1) - LEAPS_THRU_END_OF (y - 1)); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld", __func__, totaldays); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld", __func__, totaldays); y = yg; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: y: %lld", __func__, y); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: y: %lld", __func__, y); } system_time->wYear = y; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Year: %d", __func__, system_time->wYear); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Year: %d", __func__, system_time->wYear); ip = mon_yday[isleap(y)]; @@ -2789,26 +3193,27 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time, continue; } totaldays-=ip[y]; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld", __func__, totaldays); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: totaldays: %lld", __func__, totaldays); system_time->wMonth = y + 1; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Month: %d", __func__, system_time->wMonth); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Month: %d", __func__, system_time->wMonth); system_time->wDay = totaldays + 1; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Day: %d", __func__, system_time->wDay); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Day: %d", __func__, system_time->wDay); return(TRUE); } -gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data) +gpointer +mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data) { - struct _WapiHandle_find find_handle = {0}; + MonoW32HandleFind find_handle = {0}; gpointer handle; gchar *utf8_pattern = NULL, *dir_part, *entry_part; - int result; + gint result; if (pattern == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: pattern is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: pattern is NULL", __func__); SetLastError (ERROR_PATH_NOT_FOUND); return(INVALID_HANDLE_VALUE); @@ -2816,13 +3221,13 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data) utf8_pattern = mono_unicode_to_external (pattern); if (utf8_pattern == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(INVALID_HANDLE_VALUE); } - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: looking for [%s]", __func__, utf8_pattern); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: looking for [%s]", __func__, utf8_pattern); /* Figure out which bit of the pattern is the directory */ dir_part = _wapi_dirname (utf8_pattern); @@ -2879,7 +3284,7 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data) if (result < 0) { _wapi_set_last_path_error_from_errno (dir_part, NULL); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: scandir error: %s", __func__, g_strerror (errno)); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: scandir error: %s", __func__, g_strerror (errno)); g_free (utf8_pattern); g_free (entry_part); g_free (dir_part); @@ -2889,7 +3294,7 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data) g_free (utf8_pattern); g_free (entry_part); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Got %d matches", __func__, result); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Got %d matches", __func__, result); find_handle.dir_part = dir_part; find_handle.num = result; @@ -2907,8 +3312,8 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data) } if (handle != INVALID_HANDLE_VALUE && - !FindNextFile (handle, find_data)) { - FindClose (handle); + !mono_w32file_find_next (handle, find_data)) { + mono_w32file_find_close (handle); SetLastError (ERROR_NO_MORE_FILES); handle = INVALID_HANDLE_VALUE; } @@ -2916,12 +3321,13 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data) return (handle); } -gboolean FindNextFile (gpointer handle, WapiFindData *find_data) +gboolean +mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data) { - struct _WapiHandle_find *find_handle; + MonoW32HandleFind *find_handle; gboolean ok; struct stat buf, linkbuf; - int result; + gint result; gchar *filename; gchar *utf8_filename, *utf8_basename; gunichar2 *utf16_basename; @@ -2957,7 +3363,7 @@ retry: } if (result != 0) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: stat failed: %s", __func__, filename); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: stat failed: %s", __func__, filename); g_free (filename); goto retry; @@ -2966,7 +3372,7 @@ retry: #ifndef __native_client__ result = _wapi_lstat (filename, &linkbuf); if (result != 0) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lstat failed: %s", __func__, filename); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lstat failed: %s", __func__, filename); g_free (filename); goto retry; @@ -2986,7 +3392,7 @@ retry: } g_free (filename); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Found [%s]", __func__, utf8_filename); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Found [%s]", __func__, utf8_filename); /* fill data block */ @@ -3032,7 +3438,7 @@ retry: memset (find_data->cFileName, '\0', (MAX_PATH*2)); /* Truncating a utf16 string like this might leave the last - * char incomplete + * gchar incomplete */ memcpy (find_data->cFileName, utf16_basename, bytes<(MAX_PATH*2)-2?bytes:(MAX_PATH*2)-2); @@ -3049,17 +3455,10 @@ cleanup: return(ret); } -/** - * FindClose: - * @wapi_handle: the find handle to close. - * - * Closes find handle @wapi_handle - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean FindClose (gpointer handle) +gboolean +mono_w32file_find_close (gpointer handle) { - struct _WapiHandle_find *find_handle; + MonoW32HandleFind *find_handle; gboolean ok; if (handle == NULL) { @@ -3088,24 +3487,14 @@ gboolean FindClose (gpointer handle) return(TRUE); } -/** - * CreateDirectory: - * @name: a pointer to a NULL-terminated unicode string, that names - * the directory to be created. - * @security: ignored for now - * - * Creates directory @name - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean CreateDirectory (const gunichar2 *name, - WapiSecurityAttributes *security) +gboolean +mono_w32file_create_directory (const gunichar2 *name) { gchar *utf8_name; - int result; + gint result; if (name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -3113,7 +3502,7 @@ gboolean CreateDirectory (const gunichar2 *name, utf8_name = mono_unicode_to_external (name); if (utf8_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return FALSE; @@ -3131,22 +3520,14 @@ gboolean CreateDirectory (const gunichar2 *name, return FALSE; } -/** - * RemoveDirectory: - * @name: a pointer to a NULL-terminated unicode string, that names - * the directory to be removed. - * - * Removes directory @name - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean RemoveDirectory (const gunichar2 *name) +gboolean +mono_w32file_remove_directory (const gunichar2 *name) { gchar *utf8_name; - int result; + gint result; if (name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -3154,7 +3535,7 @@ gboolean RemoveDirectory (const gunichar2 *name) utf8_name = mono_unicode_to_external (name); if (utf8_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return FALSE; @@ -3172,23 +3553,16 @@ gboolean RemoveDirectory (const gunichar2 *name) return(TRUE); } -/** - * GetFileAttributes: - * @name: a pointer to a NULL-terminated unicode filename. - * - * Gets the attributes for @name; - * - * Return value: %INVALID_FILE_ATTRIBUTES on failure - */ -guint32 GetFileAttributes (const gunichar2 *name) +guint32 +mono_w32file_get_attributes (const gunichar2 *name) { gchar *utf8_name; struct stat buf, linkbuf; - int result; + gint result; guint32 ret; if (name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -3196,7 +3570,7 @@ guint32 GetFileAttributes (const gunichar2 *name) utf8_name = mono_unicode_to_external (name); if (utf8_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_PARAMETER); return (INVALID_FILE_ATTRIBUTES); @@ -3234,35 +3608,16 @@ guint32 GetFileAttributes (const gunichar2 *name) return(ret); } -/** - * GetFileAttributesEx: - * @name: a pointer to a NULL-terminated unicode filename. - * @level: must be GetFileExInfoStandard - * @info: pointer to a WapiFileAttributesData structure - * - * Gets attributes, size and filetimes for @name; - * - * Return value: %TRUE on success, %FALSE on failure - */ -gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels level, gpointer info) +gboolean +mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat) { gchar *utf8_name; - WapiFileAttributesData *data; struct stat buf, linkbuf; - time_t create_time; - int result; - - if (level != GetFileExInfoStandard) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: info level %d not supported.", __func__, - level); - - SetLastError (ERROR_INVALID_PARAMETER); - return FALSE; - } + gint result; if (name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -3270,7 +3625,7 @@ gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels lev utf8_name = mono_unicode_to_external (name); if (utf8_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_PARAMETER); return FALSE; @@ -3295,52 +3650,25 @@ gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels lev return(FALSE); } - /* fill data block */ - - data = (WapiFileAttributesData *)info; + /* fill stat block */ - if (buf.st_mtime < buf.st_ctime) - create_time = buf.st_mtime; - else - create_time = buf.st_ctime; - - data->dwFileAttributes = _wapi_stat_to_file_attributes (utf8_name, - &buf, - &linkbuf); + stat->attributes = _wapi_stat_to_file_attributes (utf8_name, &buf, &linkbuf); + stat->creation_time = (((guint64) (buf.st_mtime < buf.st_ctime ? buf.st_mtime : buf.st_ctime)) * 10 * 1000 * 1000) + 116444736000000000ULL; + stat->last_access_time = (((guint64) (buf.st_atime)) * 10 * 1000 * 1000) + 116444736000000000ULL; + stat->last_write_time = (((guint64) (buf.st_mtime)) * 10 * 1000 * 1000) + 116444736000000000ULL; + stat->length = (stat->attributes & FILE_ATTRIBUTE_DIRECTORY) ? 0 : buf.st_size; g_free (utf8_name); - - 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; - data->nFileSizeLow = 0; - } - else { - data->nFileSizeHigh = buf.st_size >> 32; - data->nFileSizeLow = buf.st_size & 0xFFFFFFFF; - } - return TRUE; } -/** - * SetFileAttributes - * @name: name of file - * @attrs: attributes to set - * - * Changes the attributes on a named file. - * - * Return value: %TRUE on success, %FALSE on failure. - */ -extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs) +gboolean +mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs) { /* FIXME: think of something clever to do on unix */ gchar *utf8_name; struct stat buf; - int result; + gint result; /* * Currently we only handle one *internal* case, with a value that is @@ -3348,7 +3676,7 @@ extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs) */ if (name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -3356,7 +3684,7 @@ extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs) utf8_name = mono_unicode_to_external (name); if (utf8_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return FALSE; @@ -3409,16 +3737,8 @@ extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs) return(TRUE); } -/** - * GetCurrentDirectory - * @length: size of the buffer - * @buffer: pointer to buffer that recieves path - * - * Retrieves the current directory for the current process. - * - * Return value: number of characters in buffer on success, zero on failure - */ -extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer) +guint32 +mono_w32file_get_cwd (guint32 length, gunichar2 *buffer) { gunichar2 *utf16_path; glong count; @@ -3430,7 +3750,7 @@ extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer) return 0; memcpy (buffer, path, strlen(path) + 1); #else - if (getcwd ((char*)buffer, length) == NULL) { + if (getcwd ((gchar*)buffer, length) == NULL) { if (errno == ERANGE) { /*buffer length is not big enough */ gchar *path = g_get_current_dir (); /*FIXME g_get_current_dir doesn't work with broken paths and calling it just to know the path length is silly*/ if (path == NULL) @@ -3458,15 +3778,8 @@ extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer) return count; } -/** - * SetCurrentDirectory - * @path: path to new directory - * - * Changes the directory path for the current process. - * - * Return value: %TRUE on success, %FALSE on failure. - */ -extern gboolean SetCurrentDirectory (const gunichar2 *path) +gboolean +mono_w32file_set_cwd (const gunichar2 *path) { gchar *utf8_path; gboolean result; @@ -3488,21 +3801,21 @@ extern gboolean SetCurrentDirectory (const gunichar2 *path) return result; } -gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe, - WapiSecurityAttributes *security G_GNUC_UNUSED, guint32 size) +gboolean +mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size) { - struct _WapiHandle_file pipe_read_handle = {0}; - struct _WapiHandle_file pipe_write_handle = {0}; + MonoW32HandleFile pipe_read_handle = {0}; + MonoW32HandleFile pipe_write_handle = {0}; gpointer read_handle; gpointer write_handle; - int filedes[2]; - int ret; + gint filedes[2]; + gint ret; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating pipe", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating pipe", __func__); ret=pipe (filedes); if(ret==-1) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error creating pipe: %s", __func__, + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error creating pipe: %s", __func__, strerror (errno)); _wapi_set_last_error_from_errno (); @@ -3511,7 +3824,7 @@ gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe, if (filedes[0] >= mono_w32handle_fd_reserve || filedes[1] >= mono_w32handle_fd_reserve) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__); SetLastError (ERROR_TOO_MANY_OPEN_FILES); @@ -3554,7 +3867,7 @@ gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe, *readpipe = read_handle; *writepipe = write_handle; - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning pipe: read handle %p, write handle %p", + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning pipe: read handle %p, write handle %p", __func__, read_handle, write_handle); return(TRUE); @@ -3562,10 +3875,11 @@ gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe, #ifdef HAVE_GETFSSTAT /* Darwin has getfsstat */ -gint32 GetLogicalDriveStrings (guint32 len, gunichar2 *buf) +gint32 +mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf) { struct statfs *stats; - int size, n, i; + gint size, n, i; gunichar2 *dir; glong length, total = 0; @@ -3609,7 +3923,7 @@ unescape_octal (gchar *str) rptr = wptr = str; while (*rptr != '\0') { if (*rptr == '\\') { - char c; + gchar c; rptr++; c = (*(rptr++) - '0') << 6; c += (*(rptr++) - '0') << 3; @@ -3654,9 +3968,10 @@ static gboolean GetLogicalDriveStrings_MountInfo (guint32 len, gunichar2 *buf, L static void append_to_mountpoint (LinuxMountInfoParseState *state); static gboolean add_drive_string (guint32 len, gunichar2 *buf, LinuxMountInfoParseState *state); -gint32 GetLogicalDriveStrings (guint32 len, gunichar2 *buf) +gint32 +mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf) { - int fd; + gint fd; gint32 ret = 0; LinuxMountInfoParseState state; gboolean (*parser)(guint32, gunichar2*, LinuxMountInfoParseState*) = NULL; @@ -3914,7 +4229,7 @@ add_drive_string (guint32 len, gunichar2 *buf, LinuxMountInfoParseState *state) } #else gint32 -GetLogicalDriveStrings (guint32 len, gunichar2 *buf) +mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf) { return GetLogicalDriveStrings_Mtab (len, buf); } @@ -4007,9 +4322,8 @@ GetLogicalDriveStrings_Mtab (guint32 len, gunichar2 *buf) #endif #if defined(HAVE_STATVFS) || defined(HAVE_STATFS) -gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_bytes_avail, - ULARGE_INTEGER *total_number_of_bytes, - ULARGE_INTEGER *total_number_of_free_bytes) +gboolean +mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_bytes_avail, guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes) { #ifdef HAVE_STATVFS struct statvfs fsstat; @@ -4018,7 +4332,7 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_byt #endif gboolean isreadonly; gchar *utf8_path_name; - int ret; + gint ret; unsigned long block_size; if (path_name == NULL) { @@ -4031,7 +4345,7 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_byt else { utf8_path_name = mono_unicode_to_external (path_name); if (utf8_path_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); SetLastError (ERROR_INVALID_NAME); return(FALSE); @@ -4058,52 +4372,51 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_byt if (ret == -1) { _wapi_set_last_error_from_errno (); - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: statvfs failed: %s", __func__, strerror (errno)); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: statvfs failed: %s", __func__, strerror (errno)); return(FALSE); } /* total number of free bytes for non-root */ if (free_bytes_avail != NULL) { if (isreadonly) { - free_bytes_avail->QuadPart = 0; + *free_bytes_avail = 0; } else { - free_bytes_avail->QuadPart = block_size * (guint64)fsstat.f_bavail; + *free_bytes_avail = block_size * (guint64)fsstat.f_bavail; } } /* total number of bytes available for non-root */ if (total_number_of_bytes != NULL) { - total_number_of_bytes->QuadPart = block_size * (guint64)fsstat.f_blocks; + *total_number_of_bytes = block_size * (guint64)fsstat.f_blocks; } /* total number of bytes available for root */ if (total_number_of_free_bytes != NULL) { if (isreadonly) { - total_number_of_free_bytes->QuadPart = 0; + *total_number_of_free_bytes = 0; } else { - total_number_of_free_bytes->QuadPart = block_size * (guint64)fsstat.f_bfree; + *total_number_of_free_bytes = block_size * (guint64)fsstat.f_bfree; } } return(TRUE); } #else -gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, ULARGE_INTEGER *free_bytes_avail, - ULARGE_INTEGER *total_number_of_bytes, - ULARGE_INTEGER *total_number_of_free_bytes) +gboolean +mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_bytes_avail, guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes) { if (free_bytes_avail != NULL) { - free_bytes_avail->QuadPart = (guint64) -1; + *free_bytes_avail = (guint64) -1; } if (total_number_of_bytes != NULL) { - total_number_of_bytes->QuadPart = (guint64) -1; + *total_number_of_bytes = (guint64) -1; } if (total_number_of_free_bytes != NULL) { - total_number_of_free_bytes->QuadPart = (guint64) -1; + *total_number_of_free_bytes = (guint64) -1; } return(TRUE); @@ -4280,7 +4593,7 @@ static guint32 _wapi_get_drive_type(const gchar* fstype) #if defined (PLATFORM_MACOSX) || defined (__linux__) static guint32 -GetDriveTypeFromPath (const char *utf8_root_path_name) +GetDriveTypeFromPath (const gchar *utf8_root_path_name) { struct statfs buf; @@ -4337,7 +4650,8 @@ GetDriveTypeFromPath (const gchar *utf8_root_path_name) } #endif -guint32 GetDriveType(const gunichar2 *root_path_name) +guint32 +mono_w32file_get_drive_type(const gunichar2 *root_path_name) { gchar *utf8_root_path_name; guint32 drive_type; @@ -4351,7 +4665,7 @@ guint32 GetDriveType(const gunichar2 *root_path_name) else { utf8_root_path_name = mono_unicode_to_external (root_path_name); if (utf8_root_path_name == NULL) { - MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__); return(DRIVE_NO_ROOT_DIR); } @@ -4395,7 +4709,7 @@ get_fstypename (gchar *utfpath) /* Linux has struct statfs which has a different layout */ gboolean -GetVolumeInformation (const gunichar2 *path, gunichar2 *volumename, int volumesize, int *outserial, int *maxcomp, int *fsflags, gunichar2 *fsbuffer, int fsbuffersize) +mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize) { gchar *utfpath; gchar *fstypename; @@ -4423,8 +4737,78 @@ GetVolumeInformation (const gunichar2 *path, gunichar2 *volumename, int volumesi } #endif +static gboolean +LockFile (gpointer handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high) +{ + MonoW32HandleFile *file_handle; + off_t offset, length; + + if (!mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle)) { + g_warning ("%s: error looking up file handle %p", __func__, handle); + SetLastError (ERROR_INVALID_HANDLE); + return FALSE; + } + + if (!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + SetLastError (ERROR_ACCESS_DENIED); + return FALSE; + } + +#ifdef HAVE_LARGE_FILE_SUPPORT + offset = ((gint64)offset_high << 32) | offset_low; + length = ((gint64)length_high << 32) | length_low; + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Locking handle %p, offset %lld, length %lld", __func__, handle, offset, length); +#else + if (offset_high > 0 || length_high > 0) { + SetLastError (ERROR_INVALID_PARAMETER); + return FALSE; + } + offset = offset_low; + length = length_low; + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Locking handle %p, offset %ld, length %ld", __func__, handle, offset, length); +#endif + + return _wapi_lock_file_region (GPOINTER_TO_UINT(handle), offset, length); +} + +static gboolean +UnlockFile (gpointer handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high) +{ + MonoW32HandleFile *file_handle; + off_t offset, length; + + if (!mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle)) { + g_warning ("%s: error looking up file handle %p", __func__, handle); + SetLastError (ERROR_INVALID_HANDLE); + return FALSE; + } + + if (!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) { + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess); + SetLastError (ERROR_ACCESS_DENIED); + return FALSE; + } + +#ifdef HAVE_LARGE_FILE_SUPPORT + offset = ((gint64)offset_high << 32) | offset_low; + length = ((gint64)length_high << 32) | length_low; + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unlocking handle %p, offset %lld, length %lld", __func__, handle, offset, length); +#else + offset = offset_low; + length = length_low; + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unlocking handle %p, offset %ld, length %ld", __func__, handle, offset, length); +#endif + + return _wapi_unlock_file_region (GPOINTER_TO_UINT(handle), offset, length); +} + void -_wapi_io_init (void) +mono_w32file_init (void) { mono_os_mutex_init (&stdhandle_mutex); mono_os_mutex_init (&file_share_mutex); @@ -4444,10 +4828,144 @@ _wapi_io_init (void) } void -_wapi_io_cleanup (void) +mono_w32file_cleanup (void) { mono_os_mutex_destroy (&file_share_mutex); - if (file_share_hash) - g_hash_table_destroy (file_share_hash); + if (file_share_table) + g_hash_table_destroy (file_share_table); +} + +gboolean +mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = MoveFile (path, dest); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = CopyFile (path, dest, !overwrite); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gint64 +mono_w32file_get_file_size (gpointer handle, gint32 *error) +{ + gint64 length; + guint32 length_hi; + + MONO_ENTER_GC_SAFE; + + length = GetFileSize (handle, &length_hi); + if(length==INVALID_FILE_SIZE) { + *error=GetLastError (); + } + + MONO_EXIT_GC_SAFE; + + return length | ((gint64)length_hi << 32); +} + +gboolean +mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gpointer +mono_w32file_get_console_input (void) +{ + gpointer handle; + + MONO_ENTER_GC_SAFE; + handle = mono_w32file_get_std_handle (STD_INPUT_HANDLE); + MONO_EXIT_GC_SAFE; + + return handle; +} + +gpointer +mono_w32file_get_console_output (void) +{ + gpointer handle; + + MONO_ENTER_GC_SAFE; + handle = mono_w32file_get_std_handle (STD_OUTPUT_HANDLE); + MONO_EXIT_GC_SAFE; + + return handle; +} + +gpointer +mono_w32file_get_console_error (void) +{ + gpointer handle; + + MONO_ENTER_GC_SAFE; + handle = mono_w32file_get_std_handle (STD_ERROR_HANDLE); + MONO_EXIT_GC_SAFE; + + return handle; } diff --git a/mono/metadata/w32file-win32-internals.h b/mono/metadata/w32file-win32-internals.h new file mode 100644 index 00000000000..0c7c97f93c6 --- /dev/null +++ b/mono/metadata/w32file-win32-internals.h @@ -0,0 +1,15 @@ +/* + * Copyright 2016 Microsoft + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ +#ifndef _MONO_METADATA_W32FILE_WIN32_INTERNALS_H_ +#define _MONO_METADATA_W32FILE_WIN32_INTERNALS_H_ + +#include +#include + +#ifdef HOST_WIN32 +#include "mono/metadata/w32file.h" +#include "mono/metadata/w32file-internals.h" +#endif /* HOST_WIN32 */ +#endif /* _MONO_METADATA_W32FILE_WIN32_INTERNALS_H_ */ diff --git a/mono/metadata/file-io-windows-uwp.c b/mono/metadata/w32file-win32-uwp.c similarity index 81% rename from mono/metadata/file-io-windows-uwp.c rename to mono/metadata/w32file-win32-uwp.c index 3af6c056c85..15062f02948 100644 --- a/mono/metadata/file-io-windows-uwp.c +++ b/mono/metadata/w32file-win32-uwp.c @@ -1,5 +1,5 @@ /* - * file-io-windows-uwp.c: UWP file-io support for Mono. + * w32file-win32-uwp.c: UWP w32file support for Mono. * * Copyright 2016 Microsoft * Licensed under the MIT license. See LICENSE file in the project root for full license information. @@ -10,10 +10,10 @@ #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) #include -#include "mono/metadata/file-io-windows-internals.h" +#include "mono/metadata/w32file-win32-internals.h" gboolean -mono_file_io_move_file (gunichar2 *path, gunichar2 *dest, gint32 *error) +mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error) { gboolean result = FALSE; MONO_ENTER_GC_SAFE; @@ -28,7 +28,7 @@ mono_file_io_move_file (gunichar2 *path, gunichar2 *dest, gint32 *error) } gboolean -mono_file_io_replace_file (gunichar2 *destinationFileName, gunichar2 *sourceFileName, +mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error) { gboolean result = FALSE; @@ -44,7 +44,7 @@ mono_file_io_replace_file (gunichar2 *destinationFileName, gunichar2 *sourceFile } gboolean -mono_file_io_copy_file (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error) +mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error) { gboolean result = FALSE; COPYFILE2_EXTENDED_PARAMETERS copy_param = {0}; @@ -64,7 +64,7 @@ mono_file_io_copy_file (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gi } gint64 -mono_file_io_get_file_size (HANDLE handle, gint32 *error) +mono_w32file_get_file_size (HANDLE handle, gint32 *error) { LARGE_INTEGER length; @@ -80,7 +80,7 @@ mono_file_io_get_file_size (HANDLE handle, gint32 *error) } gboolean -mono_file_io_lock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error) +mono_w32file_lock (HANDLE handle, gint64 position, gint64 length, gint32 *error) { gboolean result = FALSE; MONO_ENTER_GC_SAFE; @@ -97,7 +97,7 @@ mono_file_io_lock_file (HANDLE handle, gint64 position, gint64 length, gint32 *e } gboolean -mono_file_io_unlock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error) +mono_w32file_unlock (HANDLE handle, gint64 position, gint64 length, gint32 *error) { gboolean result = FALSE; MONO_ENTER_GC_SAFE; @@ -114,7 +114,7 @@ mono_file_io_unlock_file (HANDLE handle, gint64 position, gint64 length, gint32 } HANDLE -mono_file_io_get_console_output (void) +mono_w32file_get_console_output (void) { MonoError mono_error; mono_error_init (&mono_error); @@ -130,7 +130,7 @@ mono_file_io_get_console_output (void) } HANDLE -mono_file_io_get_console_input (void) +mono_w32file_get_console_input (void) { MonoError mono_error; mono_error_init (&mono_error); @@ -146,7 +146,7 @@ mono_file_io_get_console_input (void) } HANDLE -mono_file_io_get_console_error (void) +mono_w32file_get_console_error (void) { MonoError mono_error; mono_error_init (&mono_error); diff --git a/mono/metadata/w32file-win32.c b/mono/metadata/w32file-win32.c new file mode 100644 index 00000000000..7a5478cf2e5 --- /dev/null +++ b/mono/metadata/w32file-win32.c @@ -0,0 +1,358 @@ +/* + * w32file-win32.c: Windows File IO internal calls. + * + * Copyright 2016 Microsoft + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ +#include +#include + +#include +#include +#include "mono/metadata/w32file-win32-internals.h" + +void +mono_w32file_init (void) +{ +} + +void +mono_w32file_cleanup (void) +{ +} + +gunichar2 +ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar () +{ + return (gunichar2) ':'; /* colon */ +} + +gunichar2 +ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar () +{ + return (gunichar2) '\\'; /* backslash */ +} + +gunichar2 +ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar () +{ + return (gunichar2) '/'; /* forward slash */ +} + +gunichar2 +ves_icall_System_IO_MonoIO_get_PathSeparator () +{ + return (gunichar2) ';'; /* semicolon */ +} + +void ves_icall_System_IO_MonoIO_DumpHandles (void) +{ + return; +} + +gpointer +mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs) +{ + return CreateFile (name, fileaccess, sharemode, NULL, createmode, attrs, NULL); +} + +gboolean +mono_w32file_delete (const gunichar2 *name) +{ + return DeleteFile (name); +} + +gboolean +mono_w32file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread) +{ + return ReadFile (handle, buffer, numbytes, bytesread, NULL); +} + +gboolean +mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten) +{ + return WriteFile (handle, buffer, numbytes, byteswritten, NULL); +} + +gboolean +mono_w32file_flush (gpointer handle) +{ + return FlushFileBuffers (handle); +} + +gboolean +mono_w32file_truncate (gpointer handle) +{ + return SetEndOfFile (handle); +} + +guint32 +mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method) +{ + return SetFilePointer (handle, movedistance, highmovedistance, method); +} + +gint +mono_w32file_get_type (gpointer handle) +{ + return GetFileType (handle); +} + +gboolean +mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time) +{ + return GetFileTime (handle, create_time, access_time, write_time); +} + +gboolean +mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time) +{ + return SetFileTime (handle, create_time, access_time, write_time); +} + +gboolean +mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time) +{ + return FileTimeToSystemTime (file_time, system_time); +} + +gpointer +mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data) +{ + return FindFirstFile (pattern, find_data); +} + +gboolean +mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data) +{ + return FindNextFile (handle, find_data); +} + +gboolean +mono_w32file_find_close (gpointer handle) +{ + return FindClose (handle); +} + +gboolean +mono_w32file_create_directory (const gunichar2 *name) +{ + return CreateDirectory (name, NULL); +} + +gboolean +mono_w32file_remove_directory (const gunichar2 *name) +{ + return RemoveDirectory (name); +} + +guint32 +mono_w32file_get_attributes (const gunichar2 *name) +{ + return GetFileAttributes (name); +} + +gboolean +mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat) +{ + gboolean result; + WIN32_FILE_ATTRIBUTE_DATA data; + + result = GetFileAttributesEx (name, GetFileExInfoStandard, &data); + if (result) { + stat->attributes = data.dwFileAttributes; + stat->creation_time = (gint64) ((((guint64) data.ftCreationTime.dwHighDateTime) << 32) + data.ftCreationTime.dwLowDateTime); + stat->last_access_time = (gint64) ((((guint64) data.ftLastAccessTime.dwHighDateTime) << 32) + data.ftLastAccessTime.dwLowDateTime); + stat->last_write_time = (gint64) ((((guint64) data.ftLastWriteTime.dwHighDateTime) << 32) + data.ftLastWriteTime.dwLowDateTime); + stat->length = ((gint64)data.nFileSizeHigh << 32) | data.nFileSizeLow; + } + + return result; +} + +gboolean +mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs) +{ + return SetFileAttributes (name, attrs); +} + +guint32 +mono_w32file_get_cwd (guint32 length, gunichar2 *buffer) +{ + return GetCurrentDirectory (length, buffer); +} + +gboolean +mono_w32file_set_cwd (const gunichar2 *path) +{ + return SetCurrentDirectory (path); +} + +gboolean +mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size) +{ + SECURITY_ATTRIBUTES attr; + attr.nLength = sizeof(SECURITY_ATTRIBUTES); + attr.bInheritHandle = TRUE; + attr.lpSecurityDescriptor = NULL; + return CreatePipe (readpipe, writepipe, &attr, size); +} + +gboolean +mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_bytes_avail, guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes) +{ + gboolean result; + ULARGE_INTEGER *wapi_free_bytes_avail; + ULARGE_INTEGER *wapi_total_number_of_bytes; + ULARGE_INTEGER *wapi_total_number_of_free_bytes; + + result = GetDiskFreeSpaceEx (path_name, wapi_free_bytes_avail, wapi_total_number_of_bytes, wapi_total_number_of_free_bytes); + if (result) { + if (free_bytes_avail) + *free_bytes_avail = wapi_free_bytes_avail->QuadPart; + if (total_number_of_bytes) + *total_number_of_bytes = wapi_total_number_of_bytes->QuadPart; + if (total_number_of_free_bytes) + *total_number_of_free_bytes = wapi_total_number_of_free_bytes->QuadPart; + } + + return result; +} + +gboolean +mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize) +{ + return GetVolumeInformation (path, volumename, volumesize, outserial, maxcomp, fsflags, fsbuffer, fsbuffersize); +} + +#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) + +gboolean +mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = MoveFile (path, dest); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = CopyFile (path, dest, !overwrite); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +gboolean +mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error) +{ + gboolean result; + + MONO_ENTER_GC_SAFE; + + result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32); + if (!result) + *error = GetLastError (); + + MONO_EXIT_GC_SAFE; + + return result; +} + +HANDLE +mono_w32file_get_console_input (void) +{ + return GetStdHandle (STD_INPUT_HANDLE); +} + +HANDLE +mono_w32file_get_console_output (void) +{ + return GetStdHandle (STD_OUTPUT_HANDLE); +} + +HANDLE +mono_w32file_get_console_error (void) +{ + return GetStdHandle (STD_ERROR_HANDLE); +} + +gint64 +mono_w32file_get_file_size (gpointer handle, gint32 *error) +{ + gint64 length; + guint32 length_hi; + + MONO_ENTER_GC_SAFE; + + length = GetFileSize (handle, &length_hi); + if(length==INVALID_FILE_SIZE) { + *error=GetLastError (); + } + + MONO_EXIT_GC_SAFE; + + return length | ((gint64)length_hi << 32); +} + +guint32 +mono_w32file_get_drive_type (const gunichar2 *root_path_name) +{ + return GetDriveType (root_path_name); +} + +gint32 +mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf) +{ + return GetLogicalDriveStrings (len, buf); +} + +#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ diff --git a/mono/metadata/file-io.c b/mono/metadata/w32file.c similarity index 75% rename from mono/metadata/file-io.c rename to mono/metadata/w32file.c index 44fde40538c..8aabbc57537 100644 --- a/mono/metadata/file-io.c +++ b/mono/metadata/w32file.c @@ -1,5 +1,5 @@ /* - * file-io.c: File IO internal calls + * w32file.c: File IO internal calls * * Author: * Dick Porter (dick@ximian.com) @@ -28,8 +28,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -172,19 +172,7 @@ static guint32 convert_seekorigin(MonoSeekOrigin origin) static gint64 convert_filetime (const FILETIME *filetime) { - guint64 ticks = filetime->dwHighDateTime; - ticks <<= 32; - ticks += filetime->dwLowDateTime; - return (gint64)ticks; -} - -static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *data, MonoIOStat *stat) -{ - stat->attributes = data->dwFileAttributes; - stat->creation_time = convert_filetime (&data->ftCreationTime); - stat->last_access_time = convert_filetime (&data->ftLastAccessTime); - stat->last_write_time = convert_filetime (&data->ftLastWriteTime); - stat->length = ((gint64)data->nFileSizeHigh << 32) | data->nFileSizeLow; + return (gint64) ((((guint64) filetime->dwHighDateTime) << 32) + filetime->dwLowDateTime); } /* Managed file attributes have nearly but not quite the same values @@ -200,10 +188,10 @@ static guint32 convert_attrs(MonoFileAttributes attrs) } /* - * On Win32, GetFileAttributes|Ex () seems to try opening the file, - * which might lead to sharing violation errors, whereas FindFirstFile - * always succeeds. These 2 wrappers resort to FindFirstFile if - * GetFileAttributes|Ex () has failed. + * On Win32, mono_w32file_get_attributes|_ex () seems to try opening the file, + * which might lead to sharing violation errors, whereas mono_w32file_find_first + * always succeeds. These 2 wrappers resort to mono_w32file_find_first if + * mono_w32file_get_attributes|_ex () has failed. */ static guint32 get_file_attributes (const gunichar2 *path) @@ -213,7 +201,7 @@ get_file_attributes (const gunichar2 *path) HANDLE find_handle; gint32 error; - res = GetFileAttributes (path); + res = mono_w32file_get_attributes (path); if (res != -1) return res; @@ -222,47 +210,44 @@ get_file_attributes (const gunichar2 *path) if (error != ERROR_SHARING_VIOLATION) return res; - find_handle = FindFirstFile (path, &find_data); + find_handle = mono_w32file_find_first (path, &find_data); if (find_handle == INVALID_HANDLE_VALUE) return res; - FindClose (find_handle); + mono_w32file_find_close (find_handle); return find_data.dwFileAttributes; } static gboolean -get_file_attributes_ex (const gunichar2 *path, WIN32_FILE_ATTRIBUTE_DATA *data) +get_file_attributes_ex (const gunichar2 *path, MonoIOStat *stat) { gboolean res; WIN32_FIND_DATA find_data; HANDLE find_handle; gint32 error; - res = GetFileAttributesEx (path, GetFileExInfoStandard, data); + res = mono_w32file_get_attributes_ex (path, stat); if (res) return TRUE; error = GetLastError (); - if (error != ERROR_SHARING_VIOLATION) return FALSE; - find_handle = FindFirstFile (path, &find_data); + find_handle = mono_w32file_find_first (path, &find_data); if (find_handle == INVALID_HANDLE_VALUE) return FALSE; - FindClose (find_handle); - - data->dwFileAttributes = find_data.dwFileAttributes; - data->ftCreationTime = find_data.ftCreationTime; - data->ftLastAccessTime = find_data.ftLastAccessTime; - data->ftLastWriteTime = find_data.ftLastWriteTime; - data->nFileSizeHigh = find_data.nFileSizeHigh; - data->nFileSizeLow = find_data.nFileSizeLow; + mono_w32file_find_close (find_handle); + stat->attributes = find_data.dwFileAttributes; + stat->creation_time = convert_filetime (&find_data.ftCreationTime); + stat->last_access_time = convert_filetime (&find_data.ftLastAccessTime); + stat->last_write_time = convert_filetime (&find_data.ftLastWriteTime); + stat->length = ((gint64)find_data.nFileSizeHigh << 32) | find_data.nFileSizeLow; return TRUE; } @@ -276,7 +261,7 @@ ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error) *error=ERROR_SUCCESS; - ret=CreateDirectory (mono_string_chars (path), NULL); + ret=mono_w32file_create_directory (mono_string_chars (path)); if(ret==FALSE) { *error=GetLastError (); } @@ -293,7 +278,7 @@ ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error) *error=ERROR_SUCCESS; - ret=RemoveDirectory (mono_string_chars (path)); + ret=mono_w32file_remove_directory (mono_string_chars (path)); if(ret==FALSE) { *error=GetLastError (); } @@ -339,7 +324,7 @@ get_filesystem_entries (const gunichar2 *path, goto fail; } - find_handle = FindFirstFile (path_with_pattern, &data); + find_handle = mono_w32file_find_first (path_with_pattern, &data); if (find_handle == INVALID_HANDLE_VALUE) { gint32 find_error = GetLastError (); @@ -372,9 +357,9 @@ get_filesystem_entries (const gunichar2 *path, g_free (utf8_result); } - } while(FindNextFile (find_handle, &data)); + } while(mono_w32file_find_next (find_handle, &data)); - if (FindClose (find_handle) == FALSE) { + if (mono_w32file_find_close (find_handle) == FALSE) { *error = GetLastError (); goto fail; } @@ -466,7 +451,7 @@ ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoStr WIN32_FIND_DATA data; MonoError error; - hnd = FindFirstFile (mono_string_chars (path_with_pattern), &data); + hnd = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data); if (hnd == INVALID_HANDLE_VALUE) { *file_name = NULL; @@ -491,7 +476,7 @@ ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gin WIN32_FIND_DATA data; MonoError error; - res = FindNextFile (hnd, &data); + res = mono_w32file_find_next (hnd, &data); if (res == FALSE) { *file_name = NULL; @@ -512,7 +497,7 @@ ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gin MonoBoolean ves_icall_System_IO_MonoIO_FindCloseFile (HANDLE hnd) { - return FindClose (hnd); + return mono_w32file_find_close (hnd); } /* FIXME make gc suspendable */ @@ -530,7 +515,7 @@ ves_icall_System_IO_MonoIO_FindFirst (MonoString *path, *ioerror = ERROR_SUCCESS; - find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data); + find_handle = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data); if (find_handle == INVALID_HANDLE_VALUE) { gint32 find_error = GetLastError (); @@ -548,7 +533,7 @@ ves_icall_System_IO_MonoIO_FindFirst (MonoString *path, ifh->utf8_path = mono_string_to_utf8_checked (path, &error); if (mono_error_set_pending_exception (&error)) { MONO_ENTER_GC_SAFE; - FindClose (find_handle); + mono_w32file_find_close (find_handle); MONO_EXIT_GC_SAFE; g_free (ifh); return NULL; @@ -557,7 +542,7 @@ ves_icall_System_IO_MonoIO_FindFirst (MonoString *path, *handle = ifh; while (incremental_find_check_match (ifh, &data, &result) == 0){ - if (FindNextFile (find_handle, &data) == FALSE){ + if (mono_w32file_find_next (find_handle, &data) == FALSE){ int e = GetLastError (); if (e != ERROR_NO_MORE_FILES) *ioerror = e; @@ -579,7 +564,7 @@ ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint3 *error = ERROR_SUCCESS; do { - if (FindNextFile (ifh->find_handle, &data) == FALSE){ + if (mono_w32file_find_next (ifh->find_handle, &data) == FALSE){ int e = GetLastError (); if (e != ERROR_NO_MORE_FILES) *error = e; @@ -598,7 +583,7 @@ ves_icall_System_IO_MonoIO_FindClose (gpointer handle) gint32 error; MONO_ENTER_GC_SAFE; - if (FindClose (ifh->find_handle) == FALSE){ + if (mono_w32file_find_close (ifh->find_handle) == FALSE){ error = GetLastError (); } else error = ERROR_SUCCESS; @@ -624,12 +609,12 @@ ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error) *io_error=ERROR_SUCCESS; result = NULL; - res_len = GetCurrentDirectory (len, buf); + res_len = mono_w32file_get_cwd (len, buf); if (res_len > len) { /*buf is too small.*/ int old_res_len = res_len; g_free (buf); buf = g_new (gunichar2, res_len); - res_len = GetCurrentDirectory (res_len, buf) == old_res_len; + res_len = mono_w32file_get_cwd (res_len, buf) == old_res_len; } if (res_len) { @@ -655,7 +640,7 @@ ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path, *error=ERROR_SUCCESS; - ret=SetCurrentDirectory (mono_string_chars (path)); + ret=mono_w32file_set_cwd (mono_string_chars (path)); if(ret==FALSE) { *error=GetLastError (); } @@ -663,48 +648,13 @@ ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path, return(ret); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -gboolean -mono_file_io_move_file (gunichar2 *path, gunichar2 *dest, gint32 *error) -{ - gboolean result = FALSE; - MONO_ENTER_GC_SAFE; - - result = MoveFile (path, dest); - if (result == FALSE) { - *error=GetLastError (); - } - - MONO_EXIT_GC_SAFE; - return result; -} -#endif /* HAVE_CLASSIC_WINAPI_SUPPORT */ - MonoBoolean ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest, gint32 *error) { *error=ERROR_SUCCESS; - return mono_file_io_move_file (mono_string_chars (path), mono_string_chars (dest), error); + return mono_w32file_move (mono_string_chars (path), mono_string_chars (dest), error); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -gboolean -mono_file_io_replace_file (gunichar2 *destinationFileName, gunichar2 *sourceFileName, - gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error) -{ - gboolean result = FALSE; - MONO_ENTER_GC_SAFE; - - result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL); - if (result == FALSE) { - *error=GetLastError (); - } - - MONO_EXIT_GC_SAFE; - return result; -} -#endif /* HAVE_CLASSIC_WINAPI_SUPPORT */ - MonoBoolean ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName, MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors, @@ -725,33 +675,16 @@ ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString * replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS; /* FIXME: source and destination file names must not be NULL, but apparently they might be! */ - return mono_file_io_replace_file (utf16_destinationFileName, utf16_sourceFileName, + return mono_w32file_replace (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName, replaceFlags, error); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -gboolean -mono_file_io_copy_file (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error) -{ - gboolean result = FALSE; - MONO_ENTER_GC_SAFE; - - result = CopyFile (path, dest, !overwrite); - if (result == FALSE) { - *error=GetLastError (); - } - - MONO_EXIT_GC_SAFE; - return result; -} -#endif /* HAVE_CLASSIC_WINAPI_SUPPORT */ - MonoBoolean ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest, MonoBoolean overwrite, gint32 *error) { *error=ERROR_SUCCESS; - return mono_file_io_copy_file (mono_string_chars (path), mono_string_chars (dest), overwrite, error); + return mono_w32file_copy (mono_string_chars (path), mono_string_chars (dest), overwrite, error); } MonoBoolean @@ -762,7 +695,7 @@ ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error) *error=ERROR_SUCCESS; - ret=DeleteFile (mono_string_chars (path)); + ret=mono_w32file_delete (mono_string_chars (path)); if(ret==FALSE) { *error=GetLastError (); } @@ -805,7 +738,7 @@ ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs, *error=ERROR_SUCCESS; - ret=SetFileAttributes (mono_string_chars (path), + ret=mono_w32file_set_attributes (mono_string_chars (path), convert_attrs ((MonoFileAttributes)attrs)); if(ret==FALSE) { *error=GetLastError (); @@ -823,7 +756,7 @@ ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error) *error=ERROR_SUCCESS; - ret=GetFileType (handle); + ret=mono_w32file_get_type (handle); if(ret==FILE_TYPE_UNKNOWN) { /* Not necessarily an error, but the caller will have * to decide based on the error value. @@ -836,20 +769,16 @@ ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error) } MonoBoolean -ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat, - gint32 *error) +ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat, gint32 *error) { gboolean result; - WIN32_FILE_ATTRIBUTE_DATA data; MONO_ENTER_GC_SAFE; *error=ERROR_SUCCESS; - result = get_file_attributes_ex (mono_string_chars (path), &data); + result = get_file_attributes_ex (mono_string_chars (path), stat); - if (result) { - convert_win32_file_attribute_data (&data, stat); - } else { + if (!result) { *error=GetLastError (); memset (stat, 0, sizeof (MonoIOStat)); } @@ -900,9 +829,7 @@ ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode, } } - ret=CreateFile (chars, convert_access ((MonoFileAccess)access_mode), - convert_share ((MonoFileShare)share), NULL, convert_mode ((MonoFileMode)mode), - attributes, NULL); + ret=mono_w32file_create (chars, convert_access ((MonoFileAccess)access_mode), convert_share ((MonoFileShare)share), convert_mode ((MonoFileMode)mode), attributes); if(ret==INVALID_HANDLE_VALUE) { *error=GetLastError (); } @@ -949,7 +876,7 @@ ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest, buffer = mono_array_addr (dest, guchar, dest_offset); MONO_ENTER_GC_SAFE; - result = ReadFile (handle, buffer, count, &n, NULL); + result = mono_w32file_read (handle, buffer, count, &n); MONO_EXIT_GC_SAFE; if (!result) { @@ -980,7 +907,7 @@ ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src, buffer = mono_array_addr (src, guchar, src_offset); MONO_ENTER_GC_SAFE; - result = WriteFile (handle, buffer, count, &n, NULL); + result = mono_w32file_write (handle, buffer, count, &n); MONO_EXIT_GC_SAFE; if (!result) { @@ -1001,7 +928,7 @@ ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin, *error=ERROR_SUCCESS; offset_hi = offset >> 32; - offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi, + offset = mono_w32file_seek (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi, convert_seekorigin ((MonoSeekOrigin)origin)); if(offset==INVALID_SET_FILE_POINTER) { @@ -1020,7 +947,7 @@ ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error) *error=ERROR_SUCCESS; - ret=FlushFileBuffers (handle); + ret=mono_w32file_flush (handle); if(ret==FALSE) { *error=GetLastError (); } @@ -1029,30 +956,11 @@ ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error) return(ret); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -gint64 -mono_file_io_get_file_size (HANDLE handle, gint32 *error) -{ - gint64 length; - guint32 length_hi; - - MONO_ENTER_GC_SAFE; - - length = GetFileSize (handle, &length_hi); - if(length==INVALID_FILE_SIZE) { - *error=GetLastError (); - } - - MONO_EXIT_GC_SAFE; - return length | ((gint64)length_hi << 32); -} -#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ - gint64 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error) { *error=ERROR_SUCCESS; - return mono_file_io_get_file_size (handle, error); + return mono_w32file_get_file_size (handle, error); } /* FIXME make gc suspendable */ @@ -1070,7 +978,7 @@ ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length, /* save file pointer */ offset_hi = 0; - offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT); + offset = mono_w32file_seek (handle, 0, &offset_hi, FILE_CURRENT); if(offset==INVALID_SET_FILE_POINTER) { *error=GetLastError (); return(FALSE); @@ -1079,14 +987,14 @@ ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length, /* extend or truncate */ length_hi = length >> 32; - offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi, + offset_set=mono_w32file_seek (handle, length & 0xFFFFFFFF, &length_hi, FILE_BEGIN); if(offset_set==INVALID_SET_FILE_POINTER) { *error=GetLastError (); return(FALSE); } - result = SetEndOfFile (handle); + result = mono_w32file_truncate (handle); if(result==FALSE) { *error=GetLastError (); return(FALSE); @@ -1094,7 +1002,7 @@ ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length, /* restore file pointer */ - offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi, + offset_set=mono_w32file_seek (handle, offset & 0xFFFFFFFF, &offset_hi, FILE_BEGIN); if(offset_set==INVALID_SET_FILE_POINTER) { *error=GetLastError (); @@ -1111,8 +1019,8 @@ ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time, { gboolean ret; const FILETIME *creation_filetime; - const FILETIME *last_access_filetime; - const FILETIME *last_write_filetime; + const FILETIME *access_filetime; + const FILETIME *write_filetime; MONO_ENTER_GC_SAFE; *error=ERROR_SUCCESS; @@ -1123,16 +1031,16 @@ ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time, creation_filetime = (FILETIME *)&creation_time; if (last_access_time < 0) - last_access_filetime = NULL; + access_filetime = NULL; else - last_access_filetime = (FILETIME *)&last_access_time; + access_filetime = (FILETIME *)&last_access_time; if (last_write_time < 0) - last_write_filetime = NULL; + write_filetime = NULL; else - last_write_filetime = (FILETIME *)&last_write_time; + write_filetime = (FILETIME *)&last_write_time; - ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime); + ret=mono_w32file_set_times (handle, creation_filetime, access_filetime, write_filetime); if(ret==FALSE) { *error=GetLastError (); } @@ -1141,60 +1049,31 @@ ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time, return(ret); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -HANDLE -mono_file_io_get_console_output (void) -{ - return GetStdHandle (STD_OUTPUT_HANDLE); -} -#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ - HANDLE ves_icall_System_IO_MonoIO_get_ConsoleOutput () { - return mono_file_io_get_console_output (); + return mono_w32file_get_console_output (); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -HANDLE -mono_file_io_get_console_input (void) -{ - return GetStdHandle (STD_INPUT_HANDLE); -} -#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ - HANDLE ves_icall_System_IO_MonoIO_get_ConsoleInput () { - return mono_file_io_get_console_input (); -} - -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -HANDLE -mono_file_io_get_console_error (void) -{ - return GetStdHandle (STD_ERROR_HANDLE); + return mono_w32file_get_console_input (); } -#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ HANDLE ves_icall_System_IO_MonoIO_get_ConsoleError () { - return mono_file_io_get_console_error (); + return mono_w32file_get_console_error (); } MonoBoolean ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error) { - SECURITY_ATTRIBUTES attr; gboolean ret; - - attr.nLength=sizeof(SECURITY_ATTRIBUTES); - attr.bInheritHandle=TRUE; - attr.lpSecurityDescriptor=NULL; MONO_ENTER_GC_SAFE; - ret=CreatePipe (read_handle, write_handle, &attr, 0); + ret=mono_w32file_create_pipe (read_handle, write_handle, 0); MONO_EXIT_GC_SAFE; if(ret==FALSE) { @@ -1302,56 +1181,18 @@ ves_icall_System_IO_MonoIO_get_InvalidPathChars () return chars; } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -gboolean -mono_file_io_lock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error) -{ - gboolean result = FALSE; - MONO_ENTER_GC_SAFE; - - result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, - length & 0xFFFFFFFF, length >> 32); - - if (result == FALSE) { - *error = GetLastError (); - } - - MONO_EXIT_GC_SAFE; - return result; -} -#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ - void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position, gint64 length, gint32 *error) { *error=ERROR_SUCCESS; - mono_file_io_lock_file (handle, position, length, error); + mono_w32file_lock (handle, position, length, error); } -#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) -gboolean -mono_file_io_unlock_file (HANDLE handle, gint64 position, gint64 length, gint32 *error) -{ - gboolean result = FALSE; - MONO_ENTER_GC_SAFE; - - result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, - length & 0xFFFFFFFF, length >> 32); - - if (result == FALSE) { - *error = GetLastError (); - } - - MONO_EXIT_GC_SAFE; - return result; -} -#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */ - void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position, gint64 length, gint32 *error) { *error=ERROR_SUCCESS; - mono_file_io_unlock_file (handle, position, length, error); + mono_w32file_unlock (handle, position, length, error); } //Support for io-layer free mmap'd files. @@ -1402,7 +1243,6 @@ void mono_w32handle_dump (void); void ves_icall_System_IO_MonoIO_DumpHandles (void) { - mono_w32handle_dump (); } #endif /* !HOST_WIN32 */ diff --git a/mono/metadata/file-io.h b/mono/metadata/w32file.h similarity index 54% rename from mono/metadata/file-io.h rename to mono/metadata/w32file.h index b7b7320debb..05bfe9fc929 100644 --- a/mono/metadata/file-io.h +++ b/mono/metadata/w32file.h @@ -1,5 +1,5 @@ /* - * file-io.h: File IO internal calls + * w32file.h: File IO internal calls * * Authors: * Dick Porter (dick@ximian.com) @@ -10,12 +10,13 @@ * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ -#ifndef _MONO_METADATA_FILEIO_H_ -#define _MONO_METADATA_FILEIO_H_ +#ifndef _MONO_METADATA_W32FILE_H_ +#define _MONO_METADATA_W32FILE_H_ #include #include +#include "io-layer/io-layer.h" #include #include @@ -262,6 +263,8 @@ ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString * MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors, gint32 *error); +#if defined (TARGET_IOS) || defined (TARGET_ANDROID) + MONO_RT_EXTERNAL_ONLY extern gint64 mono_filesize_from_path (MonoString *path); @@ -269,9 +272,226 @@ mono_filesize_from_path (MonoString *path); extern gint64 mono_filesize_from_fd (int fd); +#endif + void ves_icall_System_IO_MonoIO_DumpHandles (void); +#if !defined(HOST_WIN32) + +#define GENERIC_READ 0x80000000 +#define GENERIC_WRITE 0x40000000 +#define GENERIC_EXECUTE 0x20000000 +#define GENERIC_ALL 0x10000000 + +#define FILE_SHARE_READ 0x00000001 +#define FILE_SHARE_WRITE 0x00000002 +#define FILE_SHARE_DELETE 0x00000004 + +#define CREATE_NEW 1 +#define CREATE_ALWAYS 2 +#define OPEN_EXISTING 3 +#define OPEN_ALWAYS 4 +#define TRUNCATE_EXISTING 5 + +#define FILE_ATTRIBUTE_READONLY 0x00000001 +#define FILE_ATTRIBUTE_HIDDEN 0x00000002 +#define FILE_ATTRIBUTE_SYSTEM 0x00000004 +#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 +#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 +#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040 +#define FILE_ATTRIBUTE_NORMAL 0x00000080 +#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 +#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 +#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 +#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 +#define FILE_ATTRIBUTE_OFFLINE 0x00001000 +#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 +#define FILE_FLAG_OPEN_NO_RECALL 0x00100000 +#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000 +#define FILE_FLAG_POSIX_SEMANTICS 0x01000000 +#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000 +#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000 +#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 +#define FILE_FLAG_RANDOM_ACCESS 0x10000000 +#define FILE_FLAG_NO_BUFFERING 0x20000000 +#define FILE_FLAG_OVERLAPPED 0x40000000 +#define FILE_FLAG_WRITE_THROUGH 0x80000000 + +#define REPLACEFILE_WRITE_THROUGH 0x00000001 +#define REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002 + +#define MAX_PATH 260 + +#define INVALID_SET_FILE_POINTER ((guint32) 0xFFFFFFFF) +#define INVALID_FILE_SIZE ((guint32) 0xFFFFFFFF) +#define INVALID_FILE_ATTRIBUTES ((guint32) 0xFFFFFFFF) + +#define FILE_TYPE_UNKNOWN 0x0000 +#define FILE_TYPE_DISK 0x0001 +#define FILE_TYPE_CHAR 0x0002 +#define FILE_TYPE_PIPE 0x0003 +#define FILE_TYPE_REMOTE 0x8000 + +#define FILE_BEGIN 0 +#define FILE_CURRENT 1 +#define FILE_END 2 + +#define DRIVE_UNKNOWN 0 +#define DRIVE_NO_ROOT_DIR 1 +#define DRIVE_REMOVABLE 2 +#define DRIVE_FIXED 3 +#define DRIVE_REMOTE 4 +#define DRIVE_CDROM 5 +#define DRIVE_RAMDISK 6 + +typedef struct { + guint16 wYear; + guint16 wMonth; + guint16 wDayOfWeek; + guint16 wDay; + guint16 wHour; + guint16 wMinute; + guint16 wSecond; + guint16 wMilliseconds; +} SYSTEMTIME; + +typedef struct { +#if G_BYTE_ORDER == G_BIG_ENDIAN + guint32 dwHighDateTime; + guint32 dwLowDateTime; +#else + guint32 dwLowDateTime; + guint32 dwHighDateTime; +#endif +} FILETIME; + +typedef struct { + guint32 dwFileAttributes; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + guint32 nFileSizeHigh; + guint32 nFileSizeLow; + guint32 dwReserved0; + guint32 dwReserved1; + gunichar2 cFileName [MAX_PATH]; + gunichar2 cAlternateFileName [14]; +} WIN32_FIND_DATA; + +#endif /* !defined(HOST_WIN32) */ + +void +mono_w32file_init (void); + +void +mono_w32file_cleanup (void); + +gpointer +mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs); + +gboolean +mono_w32file_delete (const gunichar2 *name); + +gboolean +mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread); + +gboolean +mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten); + +gboolean +mono_w32file_flush (gpointer handle); + +gboolean +mono_w32file_truncate (gpointer handle); + +guint32 +mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method); + +gboolean +mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error); + +gboolean +mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error); + +gboolean +mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error); + +gboolean +mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error); + +gboolean +mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error); + +gpointer +mono_w32file_get_console_output (void); + +gpointer +mono_w32file_get_console_error (void); + +gpointer +mono_w32file_get_console_input (void); + +gint64 +mono_w32file_get_file_size (gpointer handle, gint32 *error); + +gint +mono_w32file_get_type (gpointer handle); + +gboolean +mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time); + +gboolean +mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time); + +gboolean +mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time); + +gpointer +mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data); + +gboolean +mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data); + +gboolean +mono_w32file_find_close (gpointer handle); + +gboolean +mono_w32file_create_directory (const gunichar2 *name); + +gboolean +mono_w32file_remove_directory (const gunichar2 *name); + +guint32 +mono_w32file_get_attributes (const gunichar2 *name); + +gboolean +mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat); + +gboolean +mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs); + +guint32 +mono_w32file_get_cwd (guint32 length, gunichar2 *buffer); + +gboolean +mono_w32file_set_cwd (const gunichar2 *path); + +gboolean +mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size); + +gint32 +mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf); + +gboolean +mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_bytes_avail, guint64 *total_number_of_bytes, guint64 *total_number_of_free_bytes); + +guint32 +mono_w32file_get_drive_type (const gunichar2 *root_path_name); + +gboolean +mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize); + G_END_DECLS -#endif /* _MONO_METADATA_FILEIO_H_ */ +#endif /* _MONO_METADATA_W32FILE_H_ */ diff --git a/mono/metadata/w32handle.c b/mono/metadata/w32handle.c index d4fae9dd09e..248bf1b316f 100644 --- a/mono/metadata/w32handle.c +++ b/mono/metadata/w32handle.c @@ -250,7 +250,7 @@ mono_w32handle_unlock_handle (gpointer handle) } /* - * wapi_init: + * mono_w32handle_init: * * Initialize the io-layer. */ diff --git a/mono/metadata/w32mutex-unix.c b/mono/metadata/w32mutex-unix.c index a39f5ca2761..faf8ac6eea9 100644 --- a/mono/metadata/w32mutex-unix.c +++ b/mono/metadata/w32mutex-unix.c @@ -18,6 +18,8 @@ #include "mono/utils/mono-threads.h" #include "mono/metadata/w32handle.h" +#define MAX_PATH 260 + typedef struct { MonoNativeThreadId tid; guint32 recursion; diff --git a/mono/metadata/w32process-unix.c b/mono/metadata/w32process-unix.c index 8be10017ab6..e81b50a1acf 100644 --- a/mono/metadata/w32process-unix.c +++ b/mono/metadata/w32process-unix.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ #include #include #include +#include #ifndef MAXPATHLEN #define MAXPATHLEN 242 @@ -1886,9 +1888,9 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline, out_fd = GPOINTER_TO_UINT (startup_handles->output); err_fd = GPOINTER_TO_UINT (startup_handles->error); } else { - in_fd = GPOINTER_TO_UINT (GetStdHandle (STD_INPUT_HANDLE)); - out_fd = GPOINTER_TO_UINT (GetStdHandle (STD_OUTPUT_HANDLE)); - err_fd = GPOINTER_TO_UINT (GetStdHandle (STD_ERROR_HANDLE)); + in_fd = GPOINTER_TO_UINT (mono_w32file_get_console_input ()); + out_fd = GPOINTER_TO_UINT (mono_w32file_get_console_output ()); + err_fd = GPOINTER_TO_UINT (mono_w32file_get_console_error ()); } /* @@ -2961,14 +2963,37 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle) return(NULL); } - fd = _wapi_open (filename_ext, O_RDONLY, 0); - if (fd == -1) { - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error opening file %s: %s", __func__, filename_ext, strerror (errno)); + fd = open (filename_ext, O_RDONLY, 0); + if (fd == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) { + gint saved_errno; + gchar *located_filename; - SetLastError (_wapi_get_win32_file_error (errno)); - g_free (filename_ext); + saved_errno = errno; - return(NULL); + located_filename = mono_portability_find_file (filename_ext, TRUE); + if (!located_filename) { + errno = saved_errno; + + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error opening file %s (1): %s", __func__, filename_ext, strerror (errno)); + + g_free (filename_ext); + + SetLastError (_wapi_get_win32_file_error (errno)); + return NULL; + } + + fd = open (located_filename, O_RDONLY, 0); + if (fd == -1) { + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error opening file %s (2): %s", __func__, filename_ext, strerror (errno)); + + g_free (filename_ext); + g_free (located_filename); + + SetLastError (_wapi_get_win32_file_error (errno)); + return NULL; + } + + g_free (located_filename); } if (fstat (fd, &statbuf) == -1) { diff --git a/mono/metadata/w32process.c b/mono/metadata/w32process.c index e4a8a755ff2..78a622af653 100644 --- a/mono/metadata/w32process.c +++ b/mono/metadata/w32process.c @@ -4,6 +4,7 @@ #include "w32process.h" #include "w32process-internals.h" #include "w32process-win32-internals.h" +#include "w32file.h" #include "object.h" #include "object-internals.h" #include "class.h" diff --git a/mono/metadata/w32semaphore-unix.c b/mono/metadata/w32semaphore-unix.c index bcecd8cb558..0e88d94abe7 100644 --- a/mono/metadata/w32semaphore-unix.c +++ b/mono/metadata/w32semaphore-unix.c @@ -14,6 +14,8 @@ #include "mono/utils/mono-logger-internals.h" #include "mono/metadata/w32handle.h" +#define MAX_PATH 260 + typedef struct { guint32 val; gint32 max; diff --git a/mono/metadata/w32socket-internals.h b/mono/metadata/w32socket-internals.h index dd4c61129d0..02f5fe10844 100644 --- a/mono/metadata/w32socket-internals.h +++ b/mono/metadata/w32socket-internals.h @@ -33,16 +33,6 @@ typedef struct { gpointer buf; } WSABUF; -typedef struct { - guint32 Internal; - guint32 InternalHigh; - guint32 Offset; - guint32 OffsetHigh; - gpointer hEvent; - gpointer handle1; - gpointer handle2; -} OVERLAPPED; - typedef struct { gpointer Head; guint32 HeadLength; @@ -57,6 +47,16 @@ typedef struct { guint8 Data4[8]; } GUID; +typedef struct { + guint32 Internal; + guint32 InternalHigh; + guint32 Offset; + guint32 OffsetHigh; + gpointer hEvent; + gpointer handle1; + gpointer handle2; +} OVERLAPPED; + typedef BOOL (WINAPI *LPFN_DISCONNECTEX)(SOCKET, OVERLAPPED*, guint32, guint32); typedef BOOL (WINAPI *LPFN_TRANSMITFILE)(SOCKET, HANDLE, guint32, guint32, OVERLAPPED*, TRANSMIT_FILE_BUFFERS*, guint32); diff --git a/mono/metadata/w32socket.c b/mono/metadata/w32socket.c index 9d45ddac921..ba9156eb48b 100644 --- a/mono/metadata/w32socket.c +++ b/mono/metadata/w32socket.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/msvc/libmonoruntime.vcxproj b/msvc/libmonoruntime.vcxproj index 6c94d1ff21e..0f4d0703b7b 100644 --- a/msvc/libmonoruntime.vcxproj +++ b/msvc/libmonoruntime.vcxproj @@ -29,7 +29,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -134,9 +134,9 @@ - - - + + + diff --git a/msvc/libmonoruntime.vcxproj.filters b/msvc/libmonoruntime.vcxproj.filters index 8de9920a9ea..bc9a0c35fb6 100644 --- a/msvc/libmonoruntime.vcxproj.filters +++ b/msvc/libmonoruntime.vcxproj.filters @@ -46,7 +46,7 @@ Source Files - + Source Files @@ -250,7 +250,7 @@ Source Files - + Source Files @@ -321,7 +321,7 @@ Header Files - + Header Files @@ -534,10 +534,10 @@ Header Files - + Header Files - + Header Files diff --git a/msvc/pedump.vcxproj b/msvc/pedump.vcxproj index e997a22ae4b..57b84fab14f 100644 --- a/msvc/pedump.vcxproj +++ b/msvc/pedump.vcxproj @@ -212,8 +212,8 @@ - - + + diff --git a/msvc/pedump.vcxproj.filters b/msvc/pedump.vcxproj.filters index c7f55c9b0d1..9f25b8211b5 100644 --- a/msvc/pedump.vcxproj.filters +++ b/msvc/pedump.vcxproj.filters @@ -22,7 +22,7 @@ Source Files - + Source Files @@ -100,7 +100,7 @@ Source Files - + Source Files -- 2.25.1