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)
20 #ifdef HAVE_SYS_STAT_H
23 #ifdef HAVE_SYS_TYPES_H
24 #include <sys/types.h>
27 #include <mono/metadata/object.h>
28 #include <mono/io-layer/io-layer.h>
29 #include <mono/metadata/file-io.h>
30 #include <mono/metadata/exception.h>
31 #include <mono/metadata/appdomain.h>
32 #include <mono/metadata/marshal.h>
33 #include <mono/utils/strenc.h>
34 #include <utils/mono-io-portability.h>
38 /* conversion functions */
40 static guint32 convert_mode(MonoFileMode mono_mode)
45 case FileMode_CreateNew:
54 case FileMode_OpenOrCreate:
57 case FileMode_Truncate:
58 mode=TRUNCATE_EXISTING;
64 g_warning("System.IO.FileMode has unknown value 0x%x",
73 static guint32 convert_access(MonoFileAccess mono_access)
81 case FileAccess_Write:
84 case FileAccess_ReadWrite:
85 access=GENERIC_READ|GENERIC_WRITE;
88 g_warning("System.IO.FileAccess has unknown value 0x%x",
97 static guint32 convert_share(MonoFileShare mono_share)
101 if (mono_share & FileShare_Read) {
102 share |= FILE_SHARE_READ;
104 if (mono_share & FileShare_Write) {
105 share |= FILE_SHARE_WRITE;
107 if (mono_share & FileShare_Delete) {
108 share |= FILE_SHARE_DELETE;
111 if (mono_share & ~(FileShare_Read|FileShare_Write|FileShare_Delete)) {
112 g_warning("System.IO.FileShare has unknown value 0x%x",
122 static guint32 convert_stdhandle(guint32 fd)
128 stdhandle=STD_INPUT_HANDLE;
131 stdhandle=STD_OUTPUT_HANDLE;
134 stdhandle=STD_ERROR_HANDLE;
137 g_warning("unknown standard file descriptor %d", fd);
138 stdhandle=STD_INPUT_HANDLE;
145 static guint32 convert_seekorigin(MonoSeekOrigin origin)
150 case SeekOrigin_Begin:
151 w32origin=FILE_BEGIN;
153 case SeekOrigin_Current:
154 w32origin=FILE_CURRENT;
160 g_warning("System.IO.SeekOrigin has unknown value 0x%x",
163 w32origin=FILE_CURRENT;
169 static gint64 convert_filetime (const FILETIME *filetime)
171 guint64 ticks = filetime->dwHighDateTime;
173 ticks += filetime->dwLowDateTime;
174 return (gint64)ticks;
177 static void convert_win32_file_attribute_data (const WIN32_FILE_ATTRIBUTE_DATA *data, const gunichar2 *name, MonoIOStat *stat)
181 stat->attributes = data->dwFileAttributes;
182 stat->creation_time = convert_filetime (&data->ftCreationTime);
183 stat->last_access_time = convert_filetime (&data->ftLastAccessTime);
184 stat->last_write_time = convert_filetime (&data->ftLastWriteTime);
185 stat->length = ((gint64)data->nFileSizeHigh << 32) | data->nFileSizeLow;
191 MONO_STRUCT_SETREF (stat, name, mono_string_new_utf16 (mono_domain_get (), name, len));
194 /* Managed file attributes have nearly but not quite the same values
195 * as the w32 equivalents.
197 static guint32 convert_attrs(MonoFileAttributes attrs)
199 if(attrs & FileAttributes_Encrypted) {
200 attrs |= FILE_ATTRIBUTE_ENCRYPTED;
207 * On Win32, GetFileAttributes|Ex () seems to try opening the file,
208 * which might lead to sharing violation errors, whereas FindFirstFile
209 * always succeeds. These 2 wrappers resort to FindFirstFile if
210 * GetFileAttributes|Ex () has failed.
213 get_file_attributes (const gunichar2 *path)
216 WIN32_FIND_DATA find_data;
220 res = GetFileAttributes (path);
224 error = GetLastError ();
226 if (error != ERROR_SHARING_VIOLATION)
229 find_handle = FindFirstFile (path, &find_data);
231 if (find_handle == INVALID_HANDLE_VALUE)
234 FindClose (find_handle);
236 return find_data.dwFileAttributes;
240 get_file_attributes_ex (const gunichar2 *path, WIN32_FILE_ATTRIBUTE_DATA *data)
243 WIN32_FIND_DATA find_data;
247 res = GetFileAttributesEx (path, GetFileExInfoStandard, data);
251 error = GetLastError ();
253 if (error != ERROR_SHARING_VIOLATION)
256 find_handle = FindFirstFile (path, &find_data);
258 if (find_handle == INVALID_HANDLE_VALUE)
261 FindClose (find_handle);
263 data->dwFileAttributes = find_data.dwFileAttributes;
264 data->ftCreationTime = find_data.ftCreationTime;
265 data->ftLastAccessTime = find_data.ftLastAccessTime;
266 data->ftLastWriteTime = find_data.ftLastWriteTime;
267 data->nFileSizeHigh = find_data.nFileSizeHigh;
268 data->nFileSizeLow = find_data.nFileSizeLow;
273 /* System.IO.MonoIO internal calls */
276 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error)
282 *error=ERROR_SUCCESS;
284 ret=CreateDirectory (mono_string_chars (path), NULL);
286 *error=GetLastError ();
293 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
299 *error=ERROR_SUCCESS;
301 ret=RemoveDirectory (mono_string_chars (path));
303 *error=GetLastError ();
310 get_search_dir (MonoString *pattern)
315 p = mono_string_to_utf8 (pattern);
316 result = g_path_get_dirname (p);
322 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
323 MonoString *path_with_pattern,
324 gint attrs, gint mask,
330 WIN32_FIND_DATA data;
333 gchar *utf8_path, *utf8_result, *full_name;
338 *error = ERROR_SUCCESS;
340 domain = mono_domain_get ();
341 mask = convert_attrs (mask);
342 attributes = get_file_attributes (mono_string_chars (path));
343 if (attributes != -1) {
344 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
345 *error = ERROR_INVALID_NAME;
349 *error = GetLastError ();
353 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
354 if (find_handle == INVALID_HANDLE_VALUE) {
355 gint32 find_error = GetLastError ();
357 if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
358 /* No files, so just return an empty array */
359 result = mono_array_new (domain,
360 mono_defaults.string_class,
370 utf8_path = get_search_dir (path_with_pattern);
371 names = g_ptr_array_new ();
374 if ((data.cFileName[0] == '.' && data.cFileName[1] == 0) ||
375 (data.cFileName[0] == '.' && data.cFileName[1] == '.' && data.cFileName[2] == 0)) {
379 if ((data.dwFileAttributes & mask) == attrs) {
380 utf8_result = g_utf16_to_utf8 (data.cFileName, -1, NULL, NULL, NULL);
381 if (utf8_result == NULL) {
385 full_name = g_build_filename (utf8_path, utf8_result, NULL);
386 g_ptr_array_add (names, full_name);
388 g_free (utf8_result);
390 } while(FindNextFile (find_handle, &data));
392 if (FindClose (find_handle) == FALSE) {
393 *error = GetLastError ();
396 result = mono_array_new (domain, mono_defaults.string_class, names->len);
397 for (i = 0; i < names->len; i++) {
398 mono_array_setref (result, i, mono_string_new (domain, g_ptr_array_index (names, i)));
402 for (i = 0; i < names->len; i++) {
403 g_free (g_ptr_array_index (names, i));
405 g_ptr_array_free (names, TRUE);
418 incremental_find_check_match (IncrementalFind *handle, WIN32_FIND_DATA *data, MonoString **result)
423 if ((data->cFileName[0] == '.' && data->cFileName[1] == 0) || (data->cFileName[0] == '.' && data->cFileName[1] == '.' && data->cFileName[2] == 0))
426 utf8_result = g_utf16_to_utf8 (data->cFileName, -1, NULL, NULL, NULL);
427 if (utf8_result == NULL)
430 full_name = g_build_filename (handle->utf8_path, utf8_result, NULL);
431 g_free (utf8_result);
432 *result = mono_string_new (mono_domain_get (), full_name);
439 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
440 MonoString *path_with_pattern,
441 gint32 *result_attr, gint32 *error,
444 WIN32_FIND_DATA data;
446 IncrementalFind *ifh;
449 *error = ERROR_SUCCESS;
451 find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
453 if (find_handle == INVALID_HANDLE_VALUE) {
454 gint32 find_error = GetLastError ();
457 if (find_error == ERROR_FILE_NOT_FOUND)
464 ifh = g_new (IncrementalFind, 1);
465 ifh->find_handle = find_handle;
466 ifh->utf8_path = mono_string_to_utf8 (path);
467 ifh->domain = mono_domain_get ();
470 while (incremental_find_check_match (ifh, &data, &result) == 0){
471 if (FindNextFile (find_handle, &data) == FALSE){
472 int e = GetLastError ();
473 if (e != ERROR_NO_MORE_FILES)
478 *result_attr = data.dwFileAttributes;
484 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint32 *error)
486 IncrementalFind *ifh = handle;
487 WIN32_FIND_DATA data;
490 error = ERROR_SUCCESS;
492 if (FindNextFile (ifh->find_handle, &data) == FALSE){
493 int e = GetLastError ();
494 if (e != ERROR_NO_MORE_FILES)
498 } while (incremental_find_check_match (ifh, &data, &result) == 0);
500 *result_attr = data.dwFileAttributes;
505 ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
507 IncrementalFind *ifh = handle;
510 if (FindClose (ifh->find_handle) == FALSE){
511 error = GetLastError ();
513 error = ERROR_SUCCESS;
514 g_free (ifh->utf8_path);
521 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error)
529 len = MAX_PATH + 1; /*FIXME this is too smal under most unix systems.*/
530 buf = g_new (gunichar2, len);
532 *error=ERROR_SUCCESS;
535 res_len = GetCurrentDirectory (len, buf);
536 if (res_len > len) { /*buf is too small.*/
537 int old_res_len = res_len;
539 buf = g_new (gunichar2, res_len);
540 res_len = GetCurrentDirectory (res_len, buf) == old_res_len;
548 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
550 *error=GetLastError ();
558 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
565 *error=ERROR_SUCCESS;
567 ret=SetCurrentDirectory (mono_string_chars (path));
569 *error=GetLastError ();
576 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
583 *error=ERROR_SUCCESS;
585 ret=MoveFile (mono_string_chars (path), mono_string_chars (dest));
587 *error=GetLastError ();
594 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
595 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
599 gunichar2 *utf16_sourceFileName = NULL, *utf16_destinationFileName = NULL, *utf16_destinationBackupFileName = NULL;
600 guint32 replaceFlags = REPLACEFILE_WRITE_THROUGH;
605 utf16_sourceFileName = mono_string_chars (sourceFileName);
606 if (destinationFileName)
607 utf16_destinationFileName = mono_string_chars (destinationFileName);
608 if (destinationBackupFileName)
609 utf16_destinationBackupFileName = mono_string_chars (destinationBackupFileName);
611 *error = ERROR_SUCCESS;
612 if (ignoreMetadataErrors)
613 replaceFlags |= REPLACEFILE_IGNORE_MERGE_ERRORS;
615 ret = ReplaceFile (utf16_destinationFileName, utf16_sourceFileName, utf16_destinationBackupFileName,
616 replaceFlags, NULL, NULL);
618 *error = GetLastError ();
624 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
625 MonoBoolean overwrite, gint32 *error)
631 *error=ERROR_SUCCESS;
633 ret=CopyFile (mono_string_chars (path), mono_string_chars (dest), !overwrite);
635 *error=GetLastError ();
642 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
648 *error=ERROR_SUCCESS;
650 ret=DeleteFile (mono_string_chars (path));
652 *error=GetLastError ();
659 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
665 *error=ERROR_SUCCESS;
667 ret=get_file_attributes (mono_string_chars (path));
670 * The definition of INVALID_FILE_ATTRIBUTES in the cygwin win32
671 * headers is wrong, hence this temporary workaround.
673 * http://cygwin.com/ml/cygwin/2003-09/msg01771.html
676 /* if(ret==INVALID_FILE_ATTRIBUTES) { */
677 *error=GetLastError ();
684 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
691 *error=ERROR_SUCCESS;
693 ret=SetFileAttributes (mono_string_chars (path),
694 convert_attrs (attrs));
696 *error=GetLastError ();
703 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
709 *error=ERROR_SUCCESS;
711 ret=GetFileType (handle);
712 if(ret==FILE_TYPE_UNKNOWN) {
713 /* Not necessarily an error, but the caller will have
714 * to decide based on the error value.
716 *error=GetLastError ();
723 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
727 WIN32_FILE_ATTRIBUTE_DATA data;
731 *error=ERROR_SUCCESS;
733 result = get_file_attributes_ex (mono_string_chars (path), &data);
736 convert_win32_file_attribute_data (&data,
737 mono_string_chars (path),
740 *error=GetLastError ();
741 memset (stat, 0, sizeof (MonoIOStat));
748 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
749 gint32 access_mode, gint32 share, gint32 options,
753 int attributes, attrs;
754 gunichar2 *chars = mono_string_chars (filename);
758 *error=ERROR_SUCCESS;
761 if (options & FileOptions_Encrypted)
762 attributes = FILE_ATTRIBUTE_ENCRYPTED;
764 attributes = FILE_ATTRIBUTE_NORMAL;
765 if (options & FileOptions_DeleteOnClose)
766 attributes |= FILE_FLAG_DELETE_ON_CLOSE;
767 if (options & FileOptions_SequentialScan)
768 attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
769 if (options & FileOptions_RandomAccess)
770 attributes |= FILE_FLAG_RANDOM_ACCESS;
772 if (options & FileOptions_Temporary)
773 attributes |= FILE_ATTRIBUTE_TEMPORARY;
775 /* Not sure if we should set FILE_FLAG_OVERLAPPED, how does this mix with the "Async" bool here? */
776 if (options & FileOptions_Asynchronous)
777 attributes |= FILE_FLAG_OVERLAPPED;
779 if (options & FileOptions_WriteThrough)
780 attributes |= FILE_FLAG_WRITE_THROUGH;
782 attributes = FILE_ATTRIBUTE_NORMAL;
784 /* If we're opening a directory we need to set the extra flag
786 attrs = get_file_attributes (chars);
787 if (attrs != INVALID_FILE_ATTRIBUTES) {
788 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
789 attributes |= FILE_FLAG_BACKUP_SEMANTICS;
793 ret=CreateFile (chars, convert_access (access_mode),
794 convert_share (share), NULL, convert_mode (mode),
796 if(ret==INVALID_HANDLE_VALUE) {
797 *error=GetLastError ();
804 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
810 *error=ERROR_SUCCESS;
812 ret=CloseHandle (handle);
814 *error=GetLastError ();
821 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
822 gint32 dest_offset, gint32 count,
831 *error=ERROR_SUCCESS;
833 MONO_CHECK_ARG_NULL (dest);
835 if (dest_offset + count > mono_array_length (dest))
838 buffer = mono_array_addr (dest, guchar, dest_offset);
839 result = ReadFile (handle, buffer, count, &n, NULL);
842 *error=GetLastError ();
850 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
851 gint32 src_offset, gint32 count,
860 *error=ERROR_SUCCESS;
862 MONO_CHECK_ARG_NULL (src);
864 if (src_offset + count > mono_array_length (src))
867 buffer = mono_array_addr (src, guchar, src_offset);
868 result = WriteFile (handle, buffer, count, &n, NULL);
871 *error=GetLastError ();
879 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
886 *error=ERROR_SUCCESS;
888 offset_hi = offset >> 32;
889 offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
890 convert_seekorigin (origin));
892 if(offset==INVALID_SET_FILE_POINTER) {
893 *error=GetLastError ();
896 return offset | ((gint64)offset_hi << 32);
900 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
906 *error=ERROR_SUCCESS;
908 ret=FlushFileBuffers (handle);
910 *error=GetLastError ();
917 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
924 *error=ERROR_SUCCESS;
926 length = GetFileSize (handle, &length_hi);
927 if(length==INVALID_FILE_SIZE) {
928 *error=GetLastError ();
931 return length | ((gint64)length_hi << 32);
935 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
938 gint64 offset, offset_set;
945 *error=ERROR_SUCCESS;
947 /* save file pointer */
950 offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
951 if(offset==INVALID_SET_FILE_POINTER) {
952 *error=GetLastError ();
956 /* extend or truncate */
958 length_hi = length >> 32;
959 offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
961 if(offset_set==INVALID_SET_FILE_POINTER) {
962 *error=GetLastError ();
966 result = SetEndOfFile (handle);
968 *error=GetLastError ();
972 /* restore file pointer */
974 offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
976 if(offset_set==INVALID_SET_FILE_POINTER) {
977 *error=GetLastError ();
985 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
986 gint64 last_access_time,
987 gint64 last_write_time, gint32 *error)
990 const FILETIME *creation_filetime;
991 const FILETIME *last_access_filetime;
992 const FILETIME *last_write_filetime;
996 *error=ERROR_SUCCESS;
998 if (creation_time < 0)
999 creation_filetime = NULL;
1001 creation_filetime = (FILETIME *)&creation_time;
1003 if (last_access_time < 0)
1004 last_access_filetime = NULL;
1006 last_access_filetime = (FILETIME *)&last_access_time;
1008 if (last_write_time < 0)
1009 last_write_filetime = NULL;
1011 last_write_filetime = (FILETIME *)&last_write_time;
1013 ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
1015 *error=GetLastError ();
1022 ves_icall_System_IO_MonoIO_get_ConsoleOutput ()
1024 MONO_ARCH_SAVE_REGS;
1026 return GetStdHandle (STD_OUTPUT_HANDLE);
1030 ves_icall_System_IO_MonoIO_get_ConsoleInput ()
1032 MONO_ARCH_SAVE_REGS;
1034 return GetStdHandle (STD_INPUT_HANDLE);
1038 ves_icall_System_IO_MonoIO_get_ConsoleError ()
1040 MONO_ARCH_SAVE_REGS;
1042 return GetStdHandle (STD_ERROR_HANDLE);
1046 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
1047 HANDLE *write_handle)
1049 SECURITY_ATTRIBUTES attr;
1052 MONO_ARCH_SAVE_REGS;
1054 attr.nLength=sizeof(SECURITY_ATTRIBUTES);
1055 attr.bInheritHandle=TRUE;
1056 attr.lpSecurityDescriptor=NULL;
1058 ret=CreatePipe (read_handle, write_handle, &attr, 0);
1060 /* FIXME: throw an exception? */
1067 MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle,
1068 HANDLE source_handle, HANDLE target_process_handle, HANDLE *target_handle,
1069 gint32 access, gint32 inherit, gint32 options)
1071 /* This is only used on Windows */
1074 MONO_ARCH_SAVE_REGS;
1076 ret=DuplicateHandle (source_process_handle, source_handle, target_process_handle, target_handle, access, inherit, options);
1078 /* FIXME: throw an exception? */
1086 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
1088 #if defined (TARGET_WIN32)
1089 return (gunichar2) ':'; /* colon */
1091 return (gunichar2) '/'; /* forward slash */
1096 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
1098 #if defined (TARGET_WIN32)
1099 return (gunichar2) '\\'; /* backslash */
1101 return (gunichar2) '/'; /* forward slash */
1106 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
1108 #if defined (TARGET_WIN32)
1109 return (gunichar2) '/'; /* forward slash */
1111 if (IS_PORTABILITY_SET)
1112 return (gunichar2) '\\'; /* backslash */
1114 return (gunichar2) '/'; /* forward slash */
1119 ves_icall_System_IO_MonoIO_get_PathSeparator ()
1121 #if defined (TARGET_WIN32)
1122 return (gunichar2) ';'; /* semicolon */
1124 return (gunichar2) ':'; /* colon */
1128 static const gunichar2
1129 invalid_path_chars [] = {
1130 #if defined (TARGET_WIN32)
1131 0x0022, /* double quote, which seems allowed in MS.NET but should be rejected */
1132 0x003c, /* less than */
1133 0x003e, /* greater than */
1150 ves_icall_System_IO_MonoIO_get_InvalidPathChars ()
1156 MONO_ARCH_SAVE_REGS;
1158 domain = mono_domain_get ();
1159 n = sizeof (invalid_path_chars) / sizeof (gunichar2);
1160 chars = mono_array_new (domain, mono_defaults.char_class, n);
1162 for (i = 0; i < n; ++ i)
1163 mono_array_set (chars, gunichar2, i, invalid_path_chars [i]);
1169 ves_icall_System_IO_MonoIO_GetTempPath (MonoString **mono_name)
1174 name=g_new0 (gunichar2, 256);
1176 ret=GetTempPath (256, name);
1178 /* Buffer was too short. Try again... */
1180 name=g_new0 (gunichar2, ret+2); /* include the terminator */
1181 ret=GetTempPath (ret, name);
1186 g_message ("%s: Temp path is [%s] (len %d)", __func__, name, ret);
1189 mono_gc_wbarrier_generic_store ((gpointer) mono_name,
1190 (MonoObject*) mono_string_new_utf16 (mono_domain_get (), name, ret));
1198 void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
1199 gint64 length, gint32 *error)
1203 *error=ERROR_SUCCESS;
1205 ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
1206 length & 0xFFFFFFFF, length >> 32);
1208 *error = GetLastError ();
1212 void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
1213 gint64 length, gint32 *error)
1217 *error=ERROR_SUCCESS;
1219 ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
1220 length & 0xFFFFFFFF, length >> 32);
1222 *error = GetLastError ();
1226 //Support for io-layer free mmap'd files.
1228 #if (defined (__MACH__) && defined (TARGET_ARM)) || defined (TARGET_ANDROID)
1231 mono_filesize_from_path (MonoString *string)
1235 char *path = mono_string_to_utf8 (string);
1237 if (stat (path, &buf) == -1)
1240 res = (gint64)buf.st_size;
1247 mono_filesize_from_fd (int fd)
1251 if (fstat (fd, &buf) == -1)
1254 return (gint64)buf.st_size;