2 * file-io.c: File IO internal calls
5 * Dick Porter (dick@ximian.com)
6 * Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
9 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
10 * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
11 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
22 #ifdef HAVE_SYS_STAT_H
25 #ifdef HAVE_SYS_TYPES_H
26 #include <sys/types.h>
29 #include <mono/metadata/object.h>
30 #include <mono/io-layer/io-layer.h>
31 #include <mono/metadata/file-io.h>
32 #include <mono/metadata/exception.h>
33 #include <mono/metadata/appdomain.h>
34 #include <mono/metadata/marshal.h>
35 #include <mono/utils/strenc.h>
36 #include <utils/mono-io-portability.h>
37 #include <mono/utils/w32handle.h>
41 /* conversion functions */
43 static guint32 convert_mode(MonoFileMode mono_mode)
48 case FileMode_CreateNew:
57 case FileMode_OpenOrCreate:
60 case FileMode_Truncate:
61 mode=TRUNCATE_EXISTING;
67 g_warning("System.IO.FileMode has unknown value 0x%x",
76 static guint32 convert_access(MonoFileAccess mono_access)
84 case FileAccess_Write:
87 case FileAccess_ReadWrite:
88 access=GENERIC_READ|GENERIC_WRITE;
91 g_warning("System.IO.FileAccess has unknown value 0x%x",
100 static guint32 convert_share(MonoFileShare mono_share)
104 if (mono_share & FileShare_Read) {
105 share |= FILE_SHARE_READ;
107 if (mono_share & FileShare_Write) {
108 share |= FILE_SHARE_WRITE;
110 if (mono_share & FileShare_Delete) {
111 share |= FILE_SHARE_DELETE;
114 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
115 g_warning("System.IO.FileShare has unknown value 0x%x",
125 static guint32 convert_stdhandle(guint32 fd)
131 stdhandle=STD_INPUT_HANDLE;
134 stdhandle=STD_OUTPUT_HANDLE;
137 stdhandle=STD_ERROR_HANDLE;
140 g_warning("unknown standard file descriptor %d", fd);
141 stdhandle=STD_INPUT_HANDLE;
148 static guint32 convert_seekorigin(MonoSeekOrigin origin)
153 case SeekOrigin_Begin:
154 w32origin=FILE_BEGIN;
156 case SeekOrigin_Current:
157 w32origin=FILE_CURRENT;
163 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
166 w32origin=FILE_CURRENT;
172 static gint64 convert_filetime (const FILETIME *filetime)
174 guint64 ticks = filetime->dwHighDateTime;
176 ticks += filetime->dwLowDateTime;
177 return (gint64)ticks;
180 static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *data, MonoIOStat *stat)
182 stat->attributes = data->dwFileAttributes;
183 stat->creation_time = convert_filetime (&data->ftCreationTime);
184 stat->last_access_time = convert_filetime (&data->ftLastAccessTime);
185 stat->last_write_time = convert_filetime (&data->ftLastWriteTime);
186 stat->length = ((gint64)data->nFileSizeHigh << 32) | data->nFileSizeLow;
189 /* Managed file attributes have nearly but not quite the same values
190 * as the w32 equivalents.
192 static guint32 convert_attrs(MonoFileAttributes attrs)
194 if(attrs & FileAttributes_Encrypted) {
195 attrs = (MonoFileAttributes)(attrs | FILE_ATTRIBUTE_ENCRYPTED);
202 * On Win32, GetFileAttributes|Ex () seems to try opening the file,
203 * which might lead to sharing violation errors, whereas FindFirstFile
204 * always succeeds. These 2 wrappers resort to FindFirstFile if
205 * GetFileAttributes|Ex () has failed.
208 get_file_attributes (const gunichar2 *path)
211 WIN32_FIND_DATA find_data;
215 res = GetFileAttributes (path);
219 error = GetLastError ();
221 if (error != ERROR_SHARING_VIOLATION)
224 find_handle = FindFirstFile (path, &find_data);
226 if (find_handle == INVALID_HANDLE_VALUE)
229 FindClose (find_handle);
231 return find_data.dwFileAttributes;
235 get_file_attributes_ex (const gunichar2 *path, WIN32_FILE_ATTRIBUTE_DATA *data)
238 WIN32_FIND_DATA find_data;
242 res = GetFileAttributesEx (path, GetFileExInfoStandard, data);
246 error = GetLastError ();
248 if (error != ERROR_SHARING_VIOLATION)
251 find_handle = FindFirstFile (path, &find_data);
253 if (find_handle == INVALID_HANDLE_VALUE)
256 FindClose (find_handle);
258 data->dwFileAttributes = find_data.dwFileAttributes;
259 data->ftCreationTime = find_data.ftCreationTime;
260 data->ftLastAccessTime = find_data.ftLastAccessTime;
261 data->ftLastWriteTime = find_data.ftLastWriteTime;
262 data->nFileSizeHigh = find_data.nFileSizeHigh;
263 data->nFileSizeLow = find_data.nFileSizeLow;
268 /* System.IO.MonoIO internal calls */
271 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error)
276 *error=ERROR_SUCCESS;
278 ret=CreateDirectory (mono_string_chars (path), NULL);
280 *error=GetLastError ();
288 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
293 *error=ERROR_SUCCESS;
295 ret=RemoveDirectory (mono_string_chars (path));
297 *error=GetLastError ();
305 get_search_dir (const gunichar2 *pattern)
310 p = g_utf16_to_utf8 (pattern, -1, NULL, NULL, NULL);
311 result = g_path_get_dirname (p);
317 get_filesystem_entries (const gunichar2 *path,
318 const gunichar2 *path_with_pattern,
319 gint attrs, gint mask,
323 WIN32_FIND_DATA data;
325 GPtrArray *names = NULL;
326 gchar *utf8_path = NULL, *utf8_result, *full_name;
329 mask = convert_attrs ((MonoFileAttributes)mask);
330 attributes = get_file_attributes (path);
331 if (attributes != -1) {
332 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
333 *error = ERROR_INVALID_NAME;
337 *error = GetLastError ();
341 find_handle = FindFirstFile (path_with_pattern, &data);
342 if (find_handle == INVALID_HANDLE_VALUE) {
343 gint32 find_error = GetLastError ();
345 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
346 /* No files, so just return an empty array */
354 utf8_path = get_search_dir (path_with_pattern);
355 names = g_ptr_array_new ();
358 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
359 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
363 if ((data.dwFileAttributes & mask) == attrs) {
364 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
365 if (utf8_result == NULL) {
369 full_name = g_build_filename (utf8_path, utf8_result, NULL);
370 g_ptr_array_add (names, full_name);
372 g_free (utf8_result);
374 } while(FindNextFile (find_handle, &data));
376 if (FindClose (find_handle) == FALSE) {
377 *error = GetLastError ();
385 for (i = 0; i < names->len; i++)
386 g_free (g_ptr_array_index (names, i));
387 g_ptr_array_free (names, TRUE);
395 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
396 MonoString *path_with_pattern,
397 gint attrs, gint mask,
401 MonoDomain *domain = mono_domain_get ();
406 *ioerror = ERROR_SUCCESS;
409 names = get_filesystem_entries (mono_string_chars (path), mono_string_chars (path_with_pattern), attrs, mask, ioerror);
413 // If there's no array and no error, then return an empty array.
414 if (*ioerror == ERROR_SUCCESS) {
415 MonoArray *arr = mono_array_new_checked (domain, mono_defaults.string_class, 0, &error);
416 mono_error_set_pending_exception (&error);
422 result = mono_array_new_checked (domain, mono_defaults.string_class, names->len, &error);
423 if (mono_error_set_pending_exception (&error))
425 for (i = 0; i < names->len; i++) {
426 mono_array_setref (result, i, mono_string_new (domain, (const char *)g_ptr_array_index (names, i)));
427 g_free (g_ptr_array_index (names, i));
430 g_ptr_array_free (names, TRUE);
441 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
446 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
449 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
450 if (utf8_result == NULL)
453 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
454 g_free (utf8_result);
455 *result = mono_string_new (mono_domain_get (), full_name);
461 /* FIXME make gc suspendable */
463 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
464 MonoString *path_with_pattern,
465 gint32 *result_attr, gint32 *ioerror,
469 WIN32_FIND_DATA data;
471 IncrementalFind *ifh;
474 *ioerror = ERROR_SUCCESS;
476 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
478 if (find_handle == INVALID_HANDLE_VALUE) {
479 gint32 find_error = GetLastError ();
482 if (find_error == ERROR_FILE_NOT_FOUND)
485 *ioerror = find_error;
489 ifh = g_new (IncrementalFind, 1);
490 ifh->find_handle = find_handle;
491 ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
492 if (mono_error_set_pending_exception (&error))
494 ifh->domain = mono_domain_get ();
497 while (incremental_find_check_match (ifh, &data, &result) == 0){
498 if (FindNextFile (find_handle, &data) == FALSE){
499 int e = GetLastError ();
500 if (e != ERROR_NO_MORE_FILES)
505 *result_attr = data.dwFileAttributes;
510 /* FIXME make gc suspendable */
512 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
514 IncrementalFind *ifh = (IncrementalFind *)handle;
515 WIN32_FIND_DATA data;
518 *error = ERROR_SUCCESS;
520 if (FindNextFile (ifh->find_handle, &data) == FALSE){
521 int e = GetLastError ();
522 if (e != ERROR_NO_MORE_FILES)
526 } while (incremental_find_check_match (ifh, &data, &result) == 0);
528 *result_attr = data.dwFileAttributes;
533 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
535 IncrementalFind *ifh = (IncrementalFind *)handle;
539 if (FindClose (ifh->find_handle) == FALSE){
540 error = GetLastError ();
542 error = ERROR_SUCCESS;
543 g_free (ifh->utf8_path);
551 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
558 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
559 buf = g_new (gunichar2, len);
561 mono_error_init (&error);
562 *io_error=ERROR_SUCCESS;
565 res_len = GetCurrentDirectory (len, buf);
566 if (res_len > len) { /*buf is too small.*/
567 int old_res_len = res_len;
569 buf = g_new (gunichar2, res_len);
570 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
578 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
580 *io_error=GetLastError ();
584 mono_error_set_pending_exception (&error);
589 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
594 *error=ERROR_SUCCESS;
596 ret=SetCurrentDirectory (mono_string_chars (path));
598 *error=GetLastError ();
605 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
611 *error=ERROR_SUCCESS;
613 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
615 *error=GetLastError ();
623 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
624 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
628 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
629 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
633 utf16_sourceFileName = mono_string_chars (sourceFileName);
634 if (destinationFileName)
635 utf16_destinationFileName = mono_string_chars (destinationFileName);
636 if (destinationBackupFileName)
637 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
639 *error = ERROR_SUCCESS;
640 if (ignoreMetadataErrors)
641 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
643 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
644 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
645 replaceFlags, NULL, NULL);
647 *error = GetLastError ();
654 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
655 MonoBoolean overwrite, gint32 *error)
660 *error=ERROR_SUCCESS;
662 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
664 *error=GetLastError ();
672 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
677 *error=ERROR_SUCCESS;
679 ret=DeleteFile (mono_string_chars (path));
681 *error=GetLastError ();
689 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
694 *error=ERROR_SUCCESS;
696 ret=get_file_attributes (mono_string_chars (path));
699 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
700 * headers is wrong, hence this temporary workaround.
702 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
705 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
706 *error=GetLastError ();
714 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
720 *error=ERROR_SUCCESS;
722 ret=SetFileAttributes (mono_string_chars (path),
723 convert_attrs ((MonoFileAttributes)attrs));
725 *error=GetLastError ();
733 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
738 *error=ERROR_SUCCESS;
740 ret=GetFileType (handle);
741 if(ret==FILE_TYPE_UNKNOWN) {
742 /* Not necessarily an error, but the caller will have
743 * to decide based on the error value.
745 *error=GetLastError ();
753 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
757 WIN32_FILE_ATTRIBUTE_DATA data;
760 *error=ERROR_SUCCESS;
762 result = get_file_attributes_ex (mono_string_chars (path), &data);
765 convert_win32_file_attribute_data (&data, stat);
767 *error=GetLastError ();
768 memset (stat, 0, sizeof (MonoIOStat));
776 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
777 gint32 access_mode, gint32 share, gint32 options,
781 int attributes, attrs;
785 chars = mono_string_chars (filename);
786 *error=ERROR_SUCCESS;
789 if (options & FileOptions_Encrypted)
790 attributes = FILE_ATTRIBUTE_ENCRYPTED;
792 attributes = FILE_ATTRIBUTE_NORMAL;
793 if (options & FileOptions_DeleteOnClose)
794 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
795 if (options & FileOptions_SequentialScan)
796 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
797 if (options & FileOptions_RandomAccess)
798 attributes |= FILE_FLAG_RANDOM_ACCESS;
800 if (options & FileOptions_Temporary)
801 attributes |= FILE_ATTRIBUTE_TEMPORARY;
803 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
804 if (options & FileOptions_Asynchronous)
805 attributes |= FILE_FLAG_OVERLAPPED;
807 if (options & FileOptions_WriteThrough)
808 attributes |= FILE_FLAG_WRITE_THROUGH;
810 attributes = FILE_ATTRIBUTE_NORMAL;
812 /* If we're opening a directory we need to set the extra flag
814 attrs = get_file_attributes (chars);
815 if (attrs != INVALID_FILE_ATTRIBUTES) {
816 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
817 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
821 ret=CreateFile (chars, convert_access ((MonoFileAccess)access_mode),
822 convert_share ((MonoFileShare)share), NULL, convert_mode ((MonoFileMode)mode),
824 if(ret==INVALID_HANDLE_VALUE) {
825 *error=GetLastError ();
833 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
838 *error=ERROR_SUCCESS;
840 ret=CloseHandle (handle);
842 *error=GetLastError ();
850 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
851 gint32 dest_offset, gint32 count,
858 *error=ERROR_SUCCESS;
860 MONO_CHECK_ARG_NULL (dest, 0);
862 if (dest_offset > mono_array_length (dest) - count) {
863 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
867 buffer = mono_array_addr (dest, guchar, dest_offset);
870 result = ReadFile (handle, buffer, count, &n, NULL);
874 *error=GetLastError ();
882 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
883 gint32 src_offset, gint32 count,
890 *error=ERROR_SUCCESS;
892 MONO_CHECK_ARG_NULL (src, 0);
894 if (src_offset > mono_array_length (src) - count) {
895 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
899 buffer = mono_array_addr (src, guchar, src_offset);
901 result = WriteFile (handle, buffer, count, &n, NULL);
905 *error=GetLastError ();
913 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
919 *error=ERROR_SUCCESS;
921 offset_hi = offset >> 32;
922 offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
923 convert_seekorigin ((MonoSeekOrigin)origin));
925 if(offset==INVALID_SET_FILE_POINTER) {
926 *error=GetLastError ();
930 return offset | ((gint64)offset_hi << 32);
934 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
939 *error=ERROR_SUCCESS;
941 ret=FlushFileBuffers (handle);
943 *error=GetLastError ();
951 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
957 *error=ERROR_SUCCESS;
959 length = GetFileSize (handle, &length_hi);
960 if(length==INVALID_FILE_SIZE) {
961 *error=GetLastError ();
965 return length | ((gint64)length_hi << 32);
968 /* FIXME make gc suspendable */
970 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
973 gint64 offset, offset_set;
978 *error=ERROR_SUCCESS;
980 /* save file pointer */
983 offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
984 if(offset==INVALID_SET_FILE_POINTER) {
985 *error=GetLastError ();
989 /* extend or truncate */
991 length_hi = length >> 32;
992 offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
994 if(offset_set==INVALID_SET_FILE_POINTER) {
995 *error=GetLastError ();
999 result = SetEndOfFile (handle);
1001 *error=GetLastError ();
1005 /* restore file pointer */
1007 offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
1009 if(offset_set==INVALID_SET_FILE_POINTER) {
1010 *error=GetLastError ();
1018 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
1019 gint64 last_access_time,
1020 gint64 last_write_time, gint32 *error)
1023 const FILETIME *creation_filetime;
1024 const FILETIME *last_access_filetime;
1025 const FILETIME *last_write_filetime;
1028 *error=ERROR_SUCCESS;
1030 if (creation_time < 0)
1031 creation_filetime = NULL;
1033 creation_filetime = (FILETIME *)&creation_time;
1035 if (last_access_time < 0)
1036 last_access_filetime = NULL;
1038 last_access_filetime = (FILETIME *)&last_access_time;
1040 if (last_write_time < 0)
1041 last_write_filetime = NULL;
1043 last_write_filetime = (FILETIME *)&last_write_time;
1045 ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
1047 *error=GetLastError ();
1055 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1057 return GetStdHandle (STD_OUTPUT_HANDLE);
1061 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1063 return GetStdHandle (STD_INPUT_HANDLE);
1067 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1069 return GetStdHandle (STD_ERROR_HANDLE);
1073 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
1075 SECURITY_ATTRIBUTES attr;
1078 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1079 attr.bInheritHandle=TRUE;
1080 attr.lpSecurityDescriptor=NULL;
1083 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1087 *error = GetLastError ();
1088 /* FIXME: throw an exception? */
1096 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
1097 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
1099 /* This is only used on Windows */
1103 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1107 *error = GetLastError ();
1108 /* FIXME: throw an exception? */
1116 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1118 #if defined (TARGET_WIN32)
1119 return (gunichar2) ':'; /* colon */
1121 return (gunichar2) '/'; /* forward slash */
1126 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1128 #if defined (TARGET_WIN32)
1129 return (gunichar2) '\\'; /* backslash */
1131 return (gunichar2) '/'; /* forward slash */
1136 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1138 #if defined (TARGET_WIN32)
1139 return (gunichar2) '/'; /* forward slash */
1141 if (IS_PORTABILITY_SET)
1142 return (gunichar2) '\\'; /* backslash */
1144 return (gunichar2) '/'; /* forward slash */
1149 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1151 #if defined (TARGET_WIN32)
1152 return (gunichar2) ';'; /* semicolon */
1154 return (gunichar2) ':'; /* colon */
1158 static const gunichar2
1159 invalid_path_chars [] = {
1160 #if defined (TARGET_WIN32)
1161 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1162 0x003c, /* less than */
1163 0x003e, /* greater than */
1180 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1187 domain = mono_domain_get ();
1188 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1189 chars = mono_array_new_checked (domain, mono_defaults.char_class, n, &error);
1190 if (mono_error_set_pending_exception (&error))
1193 for (i = 0; i < n; ++ i)
1194 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1199 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1200 gint64 length, gint32 *error)
1205 *error=ERROR_SUCCESS;
1207 ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
1208 length & 0xFFFFFFFF, length >> 32);
1210 *error = GetLastError ();
1216 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1217 gint64 length, gint32 *error)
1222 *error=ERROR_SUCCESS;
1224 ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
1225 length & 0xFFFFFFFF, length >> 32);
1227 *error = GetLastError ();
1233 //Support for io-layer free mmap'd files.
1235 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1238 mono_filesize_from_path (MonoString *string)
1243 char *path = mono_string_to_utf8_checked (string, &error);
1244 mono_error_raise_exception (&error); /* OK to throw, external only without a good alternative */
1247 if (stat (path, &buf) == -1)
1250 res = (gint64)buf.st_size;
1259 mono_filesize_from_fd (int fd)
1265 res = fstat (fd, &buf);
1271 return (gint64)buf.st_size;
1276 void mono_w32handle_dump (void);
1278 void ves_icall_System_IO_MonoIO_DumpHandles (void)
1281 mono_w32handle_dump ();