2 * w32file-win32.c: Windows File IO internal calls.
4 * Copyright 2016 Microsoft
5 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
12 #include "mono/metadata/w32file-win32-internals.h"
15 mono_w32file_init (void)
20 mono_w32file_cleanup (void)
25 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar ()
27 return (gunichar2) ':'; /* colon */
31 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar ()
33 return (gunichar2) '\\'; /* backslash */
37 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar ()
39 return (gunichar2) '/'; /* forward slash */
43 ves_icall_System_IO_MonoIO_get_PathSeparator ()
45 return (gunichar2) ';'; /* semicolon */
48 void ves_icall_System_IO_MonoIO_DumpHandles (void)
54 mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
58 res = CreateFile (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
64 mono_w32file_close (gpointer handle)
68 res = CloseHandle (handle);
74 mono_w32file_delete (const gunichar2 *name)
78 res = DeleteFile (name);
84 mono_w32file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread)
88 res = ReadFile (handle, buffer, numbytes, bytesread, NULL);
94 mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten)
98 res = WriteFile (handle, buffer, numbytes, byteswritten, NULL);
104 mono_w32file_flush (gpointer handle)
108 res = FlushFileBuffers (handle);
114 mono_w32file_truncate (gpointer handle)
118 res = SetEndOfFile (handle);
124 mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method)
128 res = SetFilePointer (handle, movedistance, highmovedistance, method);
134 mono_w32file_get_type (gpointer handle)
138 res = GetFileType (handle);
144 mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time)
148 res = GetFileTime (handle, create_time, access_time, write_time);
154 mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time)
158 res = SetFileTime (handle, create_time, access_time, write_time);
164 mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time)
168 res = FileTimeToSystemTime (file_time, system_time);
174 mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
178 res = FindFirstFile (pattern, find_data);
184 mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data)
188 res = FindNextFile (handle, find_data);
194 mono_w32file_find_close (gpointer handle)
198 res = FindClose (handle);
204 mono_w32file_create_directory (const gunichar2 *name)
208 res = CreateDirectory (name, NULL);
214 mono_w32file_remove_directory (const gunichar2 *name)
218 res = RemoveDirectory (name);
224 mono_w32file_get_attributes (const gunichar2 *name)
228 res = GetFileAttributes (name);
234 mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat)
237 WIN32_FILE_ATTRIBUTE_DATA data;
240 result = GetFileAttributesEx (name, GetFileExInfoStandard, &data);
243 stat->attributes = data.dwFileAttributes;
244 stat->creation_time = (gint64) ((((guint64) data.ftCreationTime.dwHighDateTime) << 32) + data.ftCreationTime.dwLowDateTime);
245 stat->last_access_time = (gint64) ((((guint64) data.ftLastAccessTime.dwHighDateTime) << 32) + data.ftLastAccessTime.dwLowDateTime);
246 stat->last_write_time = (gint64) ((((guint64) data.ftLastWriteTime.dwHighDateTime) << 32) + data.ftLastWriteTime.dwLowDateTime);
247 stat->length = ((gint64)data.nFileSizeHigh << 32) | data.nFileSizeLow;
254 mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
258 res = SetFileAttributes (name, attrs);
264 mono_w32file_get_cwd (guint32 length, gunichar2 *buffer)
268 res = GetCurrentDirectory (length, buffer);
274 mono_w32file_set_cwd (const gunichar2 *path)
278 res = SetCurrentDirectory (path);
284 mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
287 SECURITY_ATTRIBUTES attr;
288 attr.nLength = sizeof(SECURITY_ATTRIBUTES);
289 attr.bInheritHandle = TRUE;
290 attr.lpSecurityDescriptor = NULL;
292 res = CreatePipe (readpipe, writepipe, &attr, size);
298 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)
301 ULARGE_INTEGER *wapi_free_bytes_avail;
302 ULARGE_INTEGER *wapi_total_number_of_bytes;
303 ULARGE_INTEGER *wapi_total_number_of_free_bytes;
306 result = GetDiskFreeSpaceEx (path_name, wapi_free_bytes_avail, wapi_total_number_of_bytes, wapi_total_number_of_free_bytes);
309 if (free_bytes_avail)
310 *free_bytes_avail = wapi_free_bytes_avail->QuadPart;
311 if (total_number_of_bytes)
312 *total_number_of_bytes = wapi_total_number_of_bytes->QuadPart;
313 if (total_number_of_free_bytes)
314 *total_number_of_free_bytes = wapi_total_number_of_free_bytes->QuadPart;
321 mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize)
325 res = GetVolumeInformation (path, volumename, volumesize, outserial, maxcomp, fsflags, fsbuffer, fsbuffersize);
330 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
333 mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error)
339 result = MoveFile (path, dest);
341 *error = GetLastError ();
349 mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error)
355 result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL);
357 *error = GetLastError ();
365 mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error)
371 result = CopyFile (path, dest, !overwrite);
373 *error = GetLastError ();
381 mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error)
387 result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
389 *error = GetLastError ();
397 mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error)
403 result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
405 *error = GetLastError ();
413 mono_w32file_get_console_input (void)
417 res = GetStdHandle (STD_INPUT_HANDLE);
423 mono_w32file_get_console_output (void)
427 res = GetStdHandle (STD_OUTPUT_HANDLE);
433 mono_w32file_get_console_error (void)
437 res = GetStdHandle (STD_ERROR_HANDLE);
443 mono_w32file_get_file_size (gpointer handle, gint32 *error)
450 length = GetFileSize (handle, &length_hi);
451 if(length==INVALID_FILE_SIZE) {
452 *error=GetLastError ();
457 return length | ((gint64)length_hi << 32);
461 mono_w32file_get_drive_type (const gunichar2 *root_path_name)
465 res = GetDriveType (root_path_name);
471 mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf)
475 res = GetLogicalDriveStrings (len, buf);
480 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */