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)
273 *error=ERROR_SUCCESS;
275 ret=CreateDirectory (mono_string_chars (path), NULL);
277 *error=GetLastError ();
284 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
288 *error=ERROR_SUCCESS;
290 ret=RemoveDirectory (mono_string_chars (path));
292 *error=GetLastError ();
299 get_search_dir (MonoString *pattern)
304 p = mono_string_to_utf8 (pattern);
305 result = g_path_get_dirname (p);
311 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
312 MonoString *path_with_pattern,
313 gint attrs, gint mask,
319 WIN32_FIND_DATA data;
322 gchar *utf8_path, *utf8_result, *full_name;
326 *error = ERROR_SUCCESS;
328 domain = mono_domain_get ();
329 mask = convert_attrs (mask);
330 attributes = get_file_attributes (mono_string_chars (path));
331 if (attributes != -1) {
332 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
333 *error = ERROR_INVALID_NAME;
337 *error = GetLastError ();
341 find_handle = FindFirstFile (mono_string_chars (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 ();
380 result = mono_array_new (domain, mono_defaults.string_class, names->len);
381 for (i = 0; i < names->len; i++) {
382 mono_array_setref (result, i, mono_string_new (domain, g_ptr_array_index (names, i)));
386 for (i = 0; i < names->len; i++) {
387 g_free (g_ptr_array_index (names, i));
389 g_ptr_array_free (names, TRUE);
393 // If there's no array and no error, then return an empty array.
394 if (result == NULL && *error == ERROR_SUCCESS)
395 result = mono_array_new (domain, mono_defaults.string_class, 0);
407 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
412 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
415 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
416 if (utf8_result == NULL)
419 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
420 g_free (utf8_result);
421 *result = mono_string_new (mono_domain_get (), full_name);
428 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
429 MonoString *path_with_pattern,
430 gint32 *result_attr, gint32 *error,
433 WIN32_FIND_DATA data;
435 IncrementalFind *ifh;
438 *error = ERROR_SUCCESS;
440 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
442 if (find_handle == INVALID_HANDLE_VALUE) {
443 gint32 find_error = GetLastError ();
446 if (find_error == ERROR_FILE_NOT_FOUND)
453 ifh = g_new (IncrementalFind, 1);
454 ifh->find_handle = find_handle;
455 ifh->utf8_path = mono_string_to_utf8 (path);
456 ifh->domain = mono_domain_get ();
459 while (incremental_find_check_match (ifh, &data, &result) == 0){
460 if (FindNextFile (find_handle, &data) == FALSE){
461 int e = GetLastError ();
462 if (e != ERROR_NO_MORE_FILES)
467 *result_attr = data.dwFileAttributes;
473 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
475 IncrementalFind *ifh = handle;
476 WIN32_FIND_DATA data;
479 *error = ERROR_SUCCESS;
481 if (FindNextFile (ifh->find_handle, &data) == FALSE){
482 int e = GetLastError ();
483 if (e != ERROR_NO_MORE_FILES)
487 } while (incremental_find_check_match (ifh, &data, &result) == 0);
489 *result_attr = data.dwFileAttributes;
494 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
496 IncrementalFind *ifh = handle;
499 if (FindClose (ifh->find_handle) == FALSE){
500 error = GetLastError ();
502 error = ERROR_SUCCESS;
503 g_free (ifh->utf8_path);
510 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
516 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
517 buf = g_new (gunichar2, len);
519 *error=ERROR_SUCCESS;
522 res_len = GetCurrentDirectory (len, buf);
523 if (res_len > len) { /*buf is too small.*/
524 int old_res_len = res_len;
526 buf = g_new (gunichar2, res_len);
527 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
535 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
537 *error=GetLastError ();
545 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
550 *error=ERROR_SUCCESS;
552 ret=SetCurrentDirectory (mono_string_chars (path));
554 *error=GetLastError ();
561 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
566 *error=ERROR_SUCCESS;
568 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
570 *error=GetLastError ();
577 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
578 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
582 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
583 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
586 utf16_sourceFileName = mono_string_chars (sourceFileName);
587 if (destinationFileName)
588 utf16_destinationFileName = mono_string_chars (destinationFileName);
589 if (destinationBackupFileName)
590 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
592 *error = ERROR_SUCCESS;
593 if (ignoreMetadataErrors)
594 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
596 /* FIXME: source and destination file names must not be NULL, but apparently they might be! */
597 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
598 replaceFlags, NULL, NULL);
600 *error = GetLastError ();
606 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
607 MonoBoolean overwrite, gint32 *error)
611 *error=ERROR_SUCCESS;
613 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
615 *error=GetLastError ();
622 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
626 *error=ERROR_SUCCESS;
628 ret=DeleteFile (mono_string_chars (path));
630 *error=GetLastError ();
637 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
641 *error=ERROR_SUCCESS;
643 ret=get_file_attributes (mono_string_chars (path));
646 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
647 * headers is wrong, hence this temporary workaround.
649 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
652 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
653 *error=GetLastError ();
660 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
665 *error=ERROR_SUCCESS;
667 ret=SetFileAttributes (mono_string_chars (path),
668 convert_attrs (attrs));
670 *error=GetLastError ();
677 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
681 *error=ERROR_SUCCESS;
683 ret=GetFileType (handle);
684 if(ret==FILE_TYPE_UNKNOWN) {
685 /* Not necessarily an error, but the caller will have
686 * to decide based on the error value.
688 *error=GetLastError ();
695 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
699 WIN32_FILE_ATTRIBUTE_DATA data;
701 *error=ERROR_SUCCESS;
703 result = get_file_attributes_ex (mono_string_chars (path), &data);
706 convert_win32_file_attribute_data (&data, stat);
708 *error=GetLastError ();
709 memset (stat, 0, sizeof (MonoIOStat));
716 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
717 gint32 access_mode, gint32 share, gint32 options,
721 int attributes, attrs;
722 gunichar2 *chars = mono_string_chars (filename);
724 *error=ERROR_SUCCESS;
727 if (options & FileOptions_Encrypted)
728 attributes = FILE_ATTRIBUTE_ENCRYPTED;
730 attributes = FILE_ATTRIBUTE_NORMAL;
731 if (options & FileOptions_DeleteOnClose)
732 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
733 if (options & FileOptions_SequentialScan)
734 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
735 if (options & FileOptions_RandomAccess)
736 attributes |= FILE_FLAG_RANDOM_ACCESS;
738 if (options & FileOptions_Temporary)
739 attributes |= FILE_ATTRIBUTE_TEMPORARY;
741 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
742 if (options & FileOptions_Asynchronous)
743 attributes |= FILE_FLAG_OVERLAPPED;
745 if (options & FileOptions_WriteThrough)
746 attributes |= FILE_FLAG_WRITE_THROUGH;
748 attributes = FILE_ATTRIBUTE_NORMAL;
750 /* If we're opening a directory we need to set the extra flag
752 attrs = get_file_attributes (chars);
753 if (attrs != INVALID_FILE_ATTRIBUTES) {
754 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
755 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
759 ret=CreateFile (chars, convert_access (access_mode),
760 convert_share (share), NULL, convert_mode (mode),
762 if(ret==INVALID_HANDLE_VALUE) {
763 *error=GetLastError ();
770 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
774 *error=ERROR_SUCCESS;
776 ret=CloseHandle (handle);
778 *error=GetLastError ();
785 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
786 gint32 dest_offset, gint32 count,
793 *error=ERROR_SUCCESS;
795 MONO_CHECK_ARG_NULL (dest, 0);
797 if (dest_offset > mono_array_length (dest) - count) {
798 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
802 buffer = mono_array_addr (dest, guchar, dest_offset);
803 result = ReadFile (handle, buffer, count, &n, NULL);
806 *error=GetLastError ();
814 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
815 gint32 src_offset, gint32 count,
822 *error=ERROR_SUCCESS;
824 MONO_CHECK_ARG_NULL (src, 0);
826 if (src_offset > mono_array_length (src) - count) {
827 mono_set_pending_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
831 buffer = mono_array_addr (src, guchar, src_offset);
832 result = WriteFile (handle, buffer, count, &n, NULL);
835 *error=GetLastError ();
843 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
848 *error=ERROR_SUCCESS;
850 offset_hi = offset >> 32;
851 offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
852 convert_seekorigin (origin));
854 if(offset==INVALID_SET_FILE_POINTER) {
855 *error=GetLastError ();
858 return offset | ((gint64)offset_hi << 32);
862 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
866 *error=ERROR_SUCCESS;
868 ret=FlushFileBuffers (handle);
870 *error=GetLastError ();
877 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
882 *error=ERROR_SUCCESS;
884 length = GetFileSize (handle, &length_hi);
885 if(length==INVALID_FILE_SIZE) {
886 *error=GetLastError ();
889 return length | ((gint64)length_hi << 32);
893 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
896 gint64 offset, offset_set;
901 *error=ERROR_SUCCESS;
903 /* save file pointer */
906 offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
907 if(offset==INVALID_SET_FILE_POINTER) {
908 *error=GetLastError ();
912 /* extend or truncate */
914 length_hi = length >> 32;
915 offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
917 if(offset_set==INVALID_SET_FILE_POINTER) {
918 *error=GetLastError ();
922 result = SetEndOfFile (handle);
924 *error=GetLastError ();
928 /* restore file pointer */
930 offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
932 if(offset_set==INVALID_SET_FILE_POINTER) {
933 *error=GetLastError ();
941 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
942 gint64 last_access_time,
943 gint64 last_write_time, gint32 *error)
946 const FILETIME *creation_filetime;
947 const FILETIME *last_access_filetime;
948 const FILETIME *last_write_filetime;
950 *error=ERROR_SUCCESS;
952 if (creation_time < 0)
953 creation_filetime = NULL;
955 creation_filetime = (FILETIME *)&creation_time;
957 if (last_access_time < 0)
958 last_access_filetime = NULL;
960 last_access_filetime = (FILETIME *)&last_access_time;
962 if (last_write_time < 0)
963 last_write_filetime = NULL;
965 last_write_filetime = (FILETIME *)&last_write_time;
967 ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
969 *error=GetLastError ();
976 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
978 return GetStdHandle (STD_OUTPUT_HANDLE);
982 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
984 return GetStdHandle (STD_INPUT_HANDLE);
988 ves_icall_System_IO_MonoIO_get_ConsoleError ()
990 return GetStdHandle (STD_ERROR_HANDLE);
994 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
995 HANDLE *write_handle)
997 SECURITY_ATTRIBUTES attr;
1000 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1001 attr.bInheritHandle=TRUE;
1002 attr.lpSecurityDescriptor=NULL;
1004 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1006 /* FIXME: throw an exception? */
1013 MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle,
1014 HANDLE source_handle, HANDLE target_process_handle, HANDLE *target_handle,
1015 gint32 access, gint32 inherit, gint32 options)
1017 /* This is only used on Windows */
1020 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1022 /* FIXME: throw an exception? */
1030 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1032 #if defined (TARGET_WIN32)
1033 return (gunichar2) ':'; /* colon */
1035 return (gunichar2) '/'; /* forward slash */
1040 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1042 #if defined (TARGET_WIN32)
1043 return (gunichar2) '\\'; /* backslash */
1045 return (gunichar2) '/'; /* forward slash */
1050 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1052 #if defined (TARGET_WIN32)
1053 return (gunichar2) '/'; /* forward slash */
1055 if (IS_PORTABILITY_SET)
1056 return (gunichar2) '\\'; /* backslash */
1058 return (gunichar2) '/'; /* forward slash */
1063 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1065 #if defined (TARGET_WIN32)
1066 return (gunichar2) ';'; /* semicolon */
1068 return (gunichar2) ':'; /* colon */
1072 static const gunichar2
1073 invalid_path_chars [] = {
1074 #if defined (TARGET_WIN32)
1075 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1076 0x003c, /* less than */
1077 0x003e, /* greater than */
1094 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1100 domain = mono_domain_get ();
1101 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1102 chars = mono_array_new (domain, mono_defaults.char_class, n);
1104 for (i = 0; i < n; ++ i)
1105 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1111 ves_icall_System_IO_MonoIO_GetTempPath (MonoString **mono_name)
1116 name=g_new0 (gunichar2, 256);
1118 ret=GetTempPath (256, name);
1120 /* Buffer was too short. Try again... */
1122 name=g_new0 (gunichar2, ret+2); /* include the terminator */
1123 ret=GetTempPath (ret, name);
1128 g_message ("%s: Temp path is [%s] (len %d)", __func__, name, ret);
1131 mono_gc_wbarrier_generic_store ((gpointer) mono_name,
1132 (MonoObject*) mono_string_new_utf16 (mono_domain_get (), name, ret));
1140 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1141 gint64 length, gint32 *error)
1145 *error=ERROR_SUCCESS;
1147 ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
1148 length & 0xFFFFFFFF, length >> 32);
1150 *error = GetLastError ();
1154 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1155 gint64 length, gint32 *error)
1159 *error=ERROR_SUCCESS;
1161 ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
1162 length & 0xFFFFFFFF, length >> 32);
1164 *error = GetLastError ();
1168 //Support for io-layer free mmap'd files.
1170 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
1173 mono_filesize_from_path (MonoString *string)
1177 char *path = mono_string_to_utf8 (string);
1179 if (stat (path, &buf) == -1)
1182 res = (gint64)buf.st_size;
1189 mono_filesize_from_fd (int fd)
1193 if (fstat (fd, &buf) == -1)
1196 return (gint64)buf.st_size;