3 * Windows File IO internal calls.
5 * Copyright 2016 Microsoft
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
13 #include "mono/metadata/w32file-win32-internals.h"
16 mono_w32file_init (void)
21 mono_w32file_cleanup (void)
26 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
28 return (gunichar2) ':'; /* colon */
32 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
34 return (gunichar2) '\\'; /* backslash */
38 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
40 return (gunichar2) '/'; /* forward slash */
44 ves_icall_System_IO_MonoIO_get_PathSeparator ()
46 return (gunichar2) ';'; /* semicolon */
49 void ves_icall_System_IO_MonoIO_DumpHandles (void)
55 mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
59 res = CreateFile (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
65 mono_w32file_close (gpointer handle)
69 res = CloseHandle (handle);
75 mono_w32file_delete (const gunichar2 *name)
79 res = DeleteFile (name);
85 mono_w32file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread)
89 res = ReadFile (handle, buffer, numbytes, bytesread, NULL);
95 mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten)
99 res = WriteFile (handle, buffer, numbytes, byteswritten, NULL);
105 mono_w32file_flush (gpointer handle)
109 res = FlushFileBuffers (handle);
115 mono_w32file_truncate (gpointer handle)
119 res = SetEndOfFile (handle);
125 mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method)
129 res = SetFilePointer (handle, movedistance, highmovedistance, method);
135 mono_w32file_get_type (gpointer handle)
139 res = GetFileType (handle);
145 mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time)
149 res = GetFileTime (handle, create_time, access_time, write_time);
155 mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time)
159 res = SetFileTime (handle, create_time, access_time, write_time);
165 mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time)
169 res = FileTimeToSystemTime (file_time, system_time);
175 mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
179 res = FindFirstFile (pattern, find_data);
185 mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data)
189 res = FindNextFile (handle, find_data);
195 mono_w32file_find_close (gpointer handle)
199 res = FindClose (handle);
205 mono_w32file_create_directory (const gunichar2 *name)
209 res = CreateDirectory (name, NULL);
215 mono_w32file_remove_directory (const gunichar2 *name)
219 res = RemoveDirectory (name);
225 mono_w32file_get_attributes (const gunichar2 *name)
229 res = GetFileAttributes (name);
235 mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat)
238 WIN32_FILE_ATTRIBUTE_DATA data;
241 result = GetFileAttributesEx (name, GetFileExInfoStandard, &data);
244 stat->attributes = data.dwFileAttributes;
245 stat->creation_time = (gint64) ((((guint64) data.ftCreationTime.dwHighDateTime) << 32) + data.ftCreationTime.dwLowDateTime);
246 stat->last_access_time = (gint64) ((((guint64) data.ftLastAccessTime.dwHighDateTime) << 32) + data.ftLastAccessTime.dwLowDateTime);
247 stat->last_write_time = (gint64) ((((guint64) data.ftLastWriteTime.dwHighDateTime) << 32) + data.ftLastWriteTime.dwLowDateTime);
248 stat->length = ((gint64)data.nFileSizeHigh << 32) | data.nFileSizeLow;
255 mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
259 res = SetFileAttributes (name, attrs);
265 mono_w32file_get_cwd (guint32 length, gunichar2 *buffer)
269 res = GetCurrentDirectory (length, buffer);
275 mono_w32file_set_cwd (const gunichar2 *path)
279 res = SetCurrentDirectory (path);
285 mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
288 SECURITY_ATTRIBUTES attr;
289 attr.nLength = sizeof(SECURITY_ATTRIBUTES);
290 attr.bInheritHandle = TRUE;
291 attr.lpSecurityDescriptor = NULL;
293 res = CreatePipe (readpipe, writepipe, &attr, size);
299 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)
302 ULARGE_INTEGER *wapi_free_bytes_avail;
303 ULARGE_INTEGER *wapi_total_number_of_bytes;
304 ULARGE_INTEGER *wapi_total_number_of_free_bytes;
307 result = GetDiskFreeSpaceEx (path_name, wapi_free_bytes_avail, wapi_total_number_of_bytes, wapi_total_number_of_free_bytes);
310 if (free_bytes_avail)
311 *free_bytes_avail = wapi_free_bytes_avail->QuadPart;
312 if (total_number_of_bytes)
313 *total_number_of_bytes = wapi_total_number_of_bytes->QuadPart;
314 if (total_number_of_free_bytes)
315 *total_number_of_free_bytes = wapi_total_number_of_free_bytes->QuadPart;
322 mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize)
326 res = GetVolumeInformation (path, volumename, volumesize, outserial, maxcomp, fsflags, fsbuffer, fsbuffersize);
331 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
334 mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error)
340 result = MoveFile (path, dest);
342 *error = GetLastError ();
350 mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error)
356 result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL);
358 *error = GetLastError ();
366 mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error)
372 result = CopyFile (path, dest, !overwrite);
374 *error = GetLastError ();
382 mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error)
388 result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
390 *error = GetLastError ();
398 mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error)
404 result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
406 *error = GetLastError ();
414 mono_w32file_get_console_input (void)
418 res = GetStdHandle (STD_INPUT_HANDLE);
424 mono_w32file_get_console_output (void)
428 res = GetStdHandle (STD_OUTPUT_HANDLE);
434 mono_w32file_get_console_error (void)
438 res = GetStdHandle (STD_ERROR_HANDLE);
444 mono_w32file_get_file_size (gpointer handle, gint32 *error)
451 length = GetFileSize (handle, &length_hi);
452 if(length==INVALID_FILE_SIZE) {
453 *error=GetLastError ();
458 return length | ((gint64)length_hi << 32);
462 mono_w32file_get_drive_type (const gunichar2 *root_path_name)
466 res = GetDriveType (root_path_name);
472 mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf)
476 res = GetLogicalDriveStrings (len, buf);
481 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */