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)
21 #ifdef HAVE_SYS_STAT_H
24 #ifdef HAVE_SYS_TYPES_H
25 #include <sys/types.h>
28 #include <mono/metadata/object.h>
29 #include <mono/io-layer/io-layer.h>
30 #include <mono/metadata/file-io.h>
31 #include <mono/metadata/exception.h>
32 #include <mono/metadata/appdomain.h>
33 #include <mono/metadata/marshal.h>
34 #include <mono/utils/strenc.h>
35 #include <utils/mono-io-portability.h>
39 /* conversion functions */
41 static guint32 convert_mode(MonoFileMode mono_mode)
46 case FileMode_CreateNew:
55 case FileMode_OpenOrCreate:
58 case FileMode_Truncate:
59 mode=TRUNCATE_EXISTING;
65 g_warning("System.IO.FileMode has unknown value 0x%x",
74 static guint32 convert_access(MonoFileAccess mono_access)
82 case FileAccess_Write:
85 case FileAccess_ReadWrite:
86 access=GENERIC_READ|GENERIC_WRITE;
89 g_warning("System.IO.FileAccess has unknown value 0x%x",
98 static guint32 convert_share(MonoFileShare mono_share)
102 if (mono_share & FileShare_Read) {
103 share |= FILE_SHARE_READ;
105 if (mono_share & FileShare_Write) {
106 share |= FILE_SHARE_WRITE;
108 if (mono_share & FileShare_Delete) {
109 share |= FILE_SHARE_DELETE;
112 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
113 g_warning("System.IO.FileShare has unknown value 0x%x",
123 static guint32 convert_stdhandle(guint32 fd)
129 stdhandle=STD_INPUT_HANDLE;
132 stdhandle=STD_OUTPUT_HANDLE;
135 stdhandle=STD_ERROR_HANDLE;
138 g_warning("unknown standard file descriptor %d", fd);
139 stdhandle=STD_INPUT_HANDLE;
146 static guint32 convert_seekorigin(MonoSeekOrigin origin)
151 case SeekOrigin_Begin:
152 w32origin=FILE_BEGIN;
154 case SeekOrigin_Current:
155 w32origin=FILE_CURRENT;
161 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
164 w32origin=FILE_CURRENT;
170 static gint64 convert_filetime (const FILETIME *filetime)
172 guint64 ticks = filetime->dwHighDateTime;
174 ticks += filetime->dwLowDateTime;
175 return (gint64)ticks;
178 static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *data, MonoIOStat *stat)
180 stat->attributes = data->dwFileAttributes;
181 stat->creation_time = convert_filetime (&data->ftCreationTime);
182 stat->last_access_time = convert_filetime (&data->ftLastAccessTime);
183 stat->last_write_time = convert_filetime (&data->ftLastWriteTime);
184 stat->length = ((gint64)data->nFileSizeHigh << 32) | data->nFileSizeLow;
187 /* Managed file attributes have nearly but not quite the same values
188 * as the w32 equivalents.
190 static guint32 convert_attrs(MonoFileAttributes attrs)
192 if(attrs & FileAttributes_Encrypted) {
193 attrs |= FILE_ATTRIBUTE_ENCRYPTED;
200 * On Win32, GetFileAttributes|Ex () seems to try opening the file,
201 * which might lead to sharing violation errors, whereas FindFirstFile
202 * always succeeds. These 2 wrappers resort to FindFirstFile if
203 * GetFileAttributes|Ex () has failed.
206 get_file_attributes (const gunichar2 *path)
209 WIN32_FIND_DATA find_data;
213 res = GetFileAttributes (path);
217 error = GetLastError ();
219 if (error != ERROR_SHARING_VIOLATION)
222 find_handle = FindFirstFile (path, &find_data);
224 if (find_handle == INVALID_HANDLE_VALUE)
227 FindClose (find_handle);
229 return find_data.dwFileAttributes;
233 get_file_attributes_ex (const gunichar2 *path, WIN32_FILE_ATTRIBUTE_DATA *data)
236 WIN32_FIND_DATA find_data;
240 res = GetFileAttributesEx (path, GetFileExInfoStandard, data);
244 error = GetLastError ();
246 if (error != ERROR_SHARING_VIOLATION)
249 find_handle = FindFirstFile (path, &find_data);
251 if (find_handle == INVALID_HANDLE_VALUE)
254 FindClose (find_handle);
256 data->dwFileAttributes = find_data.dwFileAttributes;
257 data->ftCreationTime = find_data.ftCreationTime;
258 data->ftLastAccessTime = find_data.ftLastAccessTime;
259 data->ftLastWriteTime = find_data.ftLastWriteTime;
260 data->nFileSizeHigh = find_data.nFileSizeHigh;
261 data->nFileSizeLow = find_data.nFileSizeLow;
266 /* System.IO.MonoIO internal calls */
269 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error)
275 *error=ERROR_SUCCESS;
277 ret=CreateDirectory (mono_string_chars (path), NULL);
279 *error=GetLastError ();
286 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
292 *error=ERROR_SUCCESS;
294 ret=RemoveDirectory (mono_string_chars (path));
296 *error=GetLastError ();
303 get_search_dir (MonoString *pattern)
308 p = mono_string_to_utf8 (pattern);
309 result = g_path_get_dirname (p);
315 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
316 MonoString *path_with_pattern,
317 gint attrs, gint mask,
323 WIN32_FIND_DATA data;
326 gchar *utf8_path, *utf8_result, *full_name;
332 *error = ERROR_SUCCESS;
334 domain = mono_domain_get ();
335 mask = convert_attrs (mask);
336 attributes = get_file_attributes (mono_string_chars (path));
337 if (attributes != -1) {
338 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
339 *error = ERROR_INVALID_NAME;
343 *error = GetLastError ();
347 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
348 if (find_handle == INVALID_HANDLE_VALUE) {
349 gint32 find_error = GetLastError ();
351 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
352 /* No files, so just return an empty array */
360 utf8_path = get_search_dir (path_with_pattern);
361 names = g_ptr_array_new ();
364 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
365 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
369 if ((data.dwFileAttributes & mask) == attrs) {
370 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
371 if (utf8_result == NULL) {
375 full_name = g_build_filename (utf8_path, utf8_result, NULL);
376 g_ptr_array_add (names, full_name);
378 g_free (utf8_result);
380 } while(FindNextFile (find_handle, &data));
382 if (FindClose (find_handle) == FALSE) {
383 *error = GetLastError ();
386 result = mono_array_new (domain, mono_defaults.string_class, names->len);
387 for (i = 0; i < names->len; i++) {
388 mono_array_setref (result, i, mono_string_new (domain, g_ptr_array_index (names, i)));
392 for (i = 0; i < names->len; i++) {
393 g_free (g_ptr_array_index (names, i));
395 g_ptr_array_free (names, TRUE);
399 // If there's no array and no error, then return an empty array.
400 if (result == NULL && *error == ERROR_SUCCESS)
401 result = mono_array_new (domain, mono_defaults.string_class, 0);
413 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
418 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
421 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
422 if (utf8_result == NULL)
425 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
426 g_free (utf8_result);
427 *result = mono_string_new (mono_domain_get (), full_name);
434 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
435 MonoString *path_with_pattern,
436 gint32 *result_attr, gint32 *error,
439 WIN32_FIND_DATA data;
441 IncrementalFind *ifh;
444 *error = ERROR_SUCCESS;
446 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
448 if (find_handle == INVALID_HANDLE_VALUE) {
449 gint32 find_error = GetLastError ();
452 if (find_error == ERROR_FILE_NOT_FOUND)
459 ifh = g_new (IncrementalFind, 1);
460 ifh->find_handle = find_handle;
461 ifh->utf8_path = mono_string_to_utf8 (path);
462 ifh->domain = mono_domain_get ();
465 while (incremental_find_check_match (ifh, &data, &result) == 0){
466 if (FindNextFile (find_handle, &data) == FALSE){
467 int e = GetLastError ();
468 if (e != ERROR_NO_MORE_FILES)
473 *result_attr = data.dwFileAttributes;
479 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
481 IncrementalFind *ifh = handle;
482 WIN32_FIND_DATA data;
485 error = ERROR_SUCCESS;
487 if (FindNextFile (ifh->find_handle, &data) == FALSE){
488 int e = GetLastError ();
489 if (e != ERROR_NO_MORE_FILES)
493 } while (incremental_find_check_match (ifh, &data, &result) == 0);
495 *result_attr = data.dwFileAttributes;
500 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
502 IncrementalFind *ifh = handle;
505 if (FindClose (ifh->find_handle) == FALSE){
506 error = GetLastError ();
508 error = ERROR_SUCCESS;
509 g_free (ifh->utf8_path);
516 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
524 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
525 buf = g_new (gunichar2, len);
527 *error=ERROR_SUCCESS;
530 res_len = GetCurrentDirectory (len, buf);
531 if (res_len > len) { /*buf is too small.*/
532 int old_res_len = res_len;
534 buf = g_new (gunichar2, res_len);
535 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
543 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
545 *error=GetLastError ();
553 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
560 *error=ERROR_SUCCESS;
562 ret=SetCurrentDirectory (mono_string_chars (path));
564 *error=GetLastError ();
571 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
578 *error=ERROR_SUCCESS;
580 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
582 *error=GetLastError ();
589 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
590 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
594 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
595 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
600 utf16_sourceFileName = mono_string_chars (sourceFileName);
601 if (destinationFileName)
602 utf16_destinationFileName = mono_string_chars (destinationFileName);
603 if (destinationBackupFileName)
604 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
606 *error = ERROR_SUCCESS;
607 if (ignoreMetadataErrors)
608 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
610 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
611 replaceFlags, NULL, NULL);
613 *error = GetLastError ();
619 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
620 MonoBoolean overwrite, gint32 *error)
626 *error=ERROR_SUCCESS;
628 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
630 *error=GetLastError ();
637 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
643 *error=ERROR_SUCCESS;
645 ret=DeleteFile (mono_string_chars (path));
647 *error=GetLastError ();
654 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
660 *error=ERROR_SUCCESS;
662 ret=get_file_attributes (mono_string_chars (path));
665 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
666 * headers is wrong, hence this temporary workaround.
668 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
671 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
672 *error=GetLastError ();
679 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
686 *error=ERROR_SUCCESS;
688 ret=SetFileAttributes (mono_string_chars (path),
689 convert_attrs (attrs));
691 *error=GetLastError ();
698 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
704 *error=ERROR_SUCCESS;
706 ret=GetFileType (handle);
707 if(ret==FILE_TYPE_UNKNOWN) {
708 /* Not necessarily an error, but the caller will have
709 * to decide based on the error value.
711 *error=GetLastError ();
718 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
722 WIN32_FILE_ATTRIBUTE_DATA data;
726 *error=ERROR_SUCCESS;
728 result = get_file_attributes_ex (mono_string_chars (path), &data);
731 convert_win32_file_attribute_data (&data, stat);
733 *error=GetLastError ();
734 memset (stat, 0, sizeof (MonoIOStat));
741 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
742 gint32 access_mode, gint32 share, gint32 options,
746 int attributes, attrs;
747 gunichar2 *chars = mono_string_chars (filename);
751 *error=ERROR_SUCCESS;
754 if (options & FileOptions_Encrypted)
755 attributes = FILE_ATTRIBUTE_ENCRYPTED;
757 attributes = FILE_ATTRIBUTE_NORMAL;
758 if (options & FileOptions_DeleteOnClose)
759 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
760 if (options & FileOptions_SequentialScan)
761 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
762 if (options & FileOptions_RandomAccess)
763 attributes |= FILE_FLAG_RANDOM_ACCESS;
765 if (options & FileOptions_Temporary)
766 attributes |= FILE_ATTRIBUTE_TEMPORARY;
768 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
769 if (options & FileOptions_Asynchronous)
770 attributes |= FILE_FLAG_OVERLAPPED;
772 if (options & FileOptions_WriteThrough)
773 attributes |= FILE_FLAG_WRITE_THROUGH;
775 attributes = FILE_ATTRIBUTE_NORMAL;
777 /* If we're opening a directory we need to set the extra flag
779 attrs = get_file_attributes (chars);
780 if (attrs != INVALID_FILE_ATTRIBUTES) {
781 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
782 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
786 ret=CreateFile (chars, convert_access (access_mode),
787 convert_share (share), NULL, convert_mode (mode),
789 if(ret==INVALID_HANDLE_VALUE) {
790 *error=GetLastError ();
797 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
803 *error=ERROR_SUCCESS;
805 ret=CloseHandle (handle);
807 *error=GetLastError ();
814 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
815 gint32 dest_offset, gint32 count,
824 *error=ERROR_SUCCESS;
826 MONO_CHECK_ARG_NULL (dest);
828 if (dest_offset + count > mono_array_length (dest))
831 buffer = mono_array_addr (dest, guchar, dest_offset);
832 result = ReadFile (handle, buffer, count, &n, NULL);
835 *error=GetLastError ();
843 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
844 gint32 src_offset, gint32 count,
853 *error=ERROR_SUCCESS;
855 MONO_CHECK_ARG_NULL (src);
857 if (src_offset + count > mono_array_length (src))
860 buffer = mono_array_addr (src, guchar, src_offset);
861 result = WriteFile (handle, buffer, count, &n, NULL);
864 *error=GetLastError ();
872 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
879 *error=ERROR_SUCCESS;
881 offset_hi = offset >> 32;
882 offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
883 convert_seekorigin (origin));
885 if(offset==INVALID_SET_FILE_POINTER) {
886 *error=GetLastError ();
889 return offset | ((gint64)offset_hi << 32);
893 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
899 *error=ERROR_SUCCESS;
901 ret=FlushFileBuffers (handle);
903 *error=GetLastError ();
910 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
917 *error=ERROR_SUCCESS;
919 length = GetFileSize (handle, &length_hi);
920 if(length==INVALID_FILE_SIZE) {
921 *error=GetLastError ();
924 return length | ((gint64)length_hi << 32);
928 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
931 gint64 offset, offset_set;
938 *error=ERROR_SUCCESS;
940 /* save file pointer */
943 offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
944 if(offset==INVALID_SET_FILE_POINTER) {
945 *error=GetLastError ();
949 /* extend or truncate */
951 length_hi = length >> 32;
952 offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
954 if(offset_set==INVALID_SET_FILE_POINTER) {
955 *error=GetLastError ();
959 result = SetEndOfFile (handle);
961 *error=GetLastError ();
965 /* restore file pointer */
967 offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
969 if(offset_set==INVALID_SET_FILE_POINTER) {
970 *error=GetLastError ();
978 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
979 gint64 last_access_time,
980 gint64 last_write_time, gint32 *error)
983 const FILETIME *creation_filetime;
984 const FILETIME *last_access_filetime;
985 const FILETIME *last_write_filetime;
989 *error=ERROR_SUCCESS;
991 if (creation_time < 0)
992 creation_filetime = NULL;
994 creation_filetime = (FILETIME *)&creation_time;
996 if (last_access_time < 0)
997 last_access_filetime = NULL;
999 last_access_filetime = (FILETIME *)&last_access_time;
1001 if (last_write_time < 0)
1002 last_write_filetime = NULL;
1004 last_write_filetime = (FILETIME *)&last_write_time;
1006 ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
1008 *error=GetLastError ();
1015 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1017 MONO_ARCH_SAVE_REGS;
1019 return GetStdHandle (STD_OUTPUT_HANDLE);
1023 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1025 MONO_ARCH_SAVE_REGS;
1027 return GetStdHandle (STD_INPUT_HANDLE);
1031 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1033 MONO_ARCH_SAVE_REGS;
1035 return GetStdHandle (STD_ERROR_HANDLE);
1039 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
1040 HANDLE *write_handle)
1042 SECURITY_ATTRIBUTES attr;
1045 MONO_ARCH_SAVE_REGS;
1047 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1048 attr.bInheritHandle=TRUE;
1049 attr.lpSecurityDescriptor=NULL;
1051 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1053 /* FIXME: throw an exception? */
1060 MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle,
1061 HANDLE source_handle, HANDLE target_process_handle, HANDLE *target_handle,
1062 gint32 access, gint32 inherit, gint32 options)
1064 /* This is only used on Windows */
1067 MONO_ARCH_SAVE_REGS;
1069 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1071 /* FIXME: throw an exception? */
1079 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1081 #if defined (TARGET_WIN32)
1082 return (gunichar2) ':'; /* colon */
1084 return (gunichar2) '/'; /* forward slash */
1089 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1091 #if defined (TARGET_WIN32)
1092 return (gunichar2) '\\'; /* backslash */
1094 return (gunichar2) '/'; /* forward slash */
1099 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1101 #if defined (TARGET_WIN32)
1102 return (gunichar2) '/'; /* forward slash */
1104 if (IS_PORTABILITY_SET)
1105 return (gunichar2) '\\'; /* backslash */
1107 return (gunichar2) '/'; /* forward slash */
1112 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1114 #if defined (TARGET_WIN32)
1115 return (gunichar2) ';'; /* semicolon */
1117 return (gunichar2) ':'; /* colon */
1121 static const gunichar2
1122 invalid_path_chars [] = {
1123 #if defined (TARGET_WIN32)
1124 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1125 0x003c, /* less than */
1126 0x003e, /* greater than */
1143 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1149 MONO_ARCH_SAVE_REGS;
1151 domain = mono_domain_get ();
1152 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1153 chars = mono_array_new (domain, mono_defaults.char_class, n);
1155 for (i = 0; i < n; ++ i)
1156 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1162 ves_icall_System_IO_MonoIO_GetTempPath (MonoString **mono_name)
1167 name=g_new0 (gunichar2, 256);
1169 ret=GetTempPath (256, name);
1171 /* Buffer was too short. Try again... */
1173 name=g_new0 (gunichar2, ret+2); /* include the terminator */
1174 ret=GetTempPath (ret, name);
1179 g_message ("%s: Temp path is [%s] (len %d)", __func__, name, ret);
1182 mono_gc_wbarrier_generic_store ((gpointer) mono_name,
1183 (MonoObject*) mono_string_new_utf16 (mono_domain_get (), name, ret));
1191 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1192 gint64 length, gint32 *error)
1196 *error=ERROR_SUCCESS;
1198 ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
1199 length & 0xFFFFFFFF, length >> 32);
1201 *error = GetLastError ();
1205 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1206 gint64 length, gint32 *error)
1210 *error=ERROR_SUCCESS;
1212 ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
1213 length & 0xFFFFFFFF, length >> 32);
1215 *error = GetLastError ();
1219 //Support for io-layer free mmap'd files.
1221 #if (defined (__MACH__) && defined (TARGET_ARM)) || defined (TARGET_ANDROID)
1224 mono_filesize_from_path (MonoString *string)
1228 char *path = mono_string_to_utf8 (string);
1230 if (stat (path, &buf) == -1)
1233 res = (gint64)buf.st_size;
1240 mono_filesize_from_fd (int fd)
1244 if (fstat (fd, &buf) == -1)
1247 return (gint64)buf.st_size;