Pass the --clr-memory-model flag on the command line instead of MONO_DEBUG so its...
[mono-project.git] / mono / metadata / w32file.h
blobac685713557948363424788ca435242adff1ae92
1 /**
2 * \file
3 * File IO internal calls
5 * Authors:
6 * Dick Porter (dick@ximian.com)
7 * Dan Lewis (dihlewis@yahoo.co.uk)
9 * (C) 2001 Ximian, Inc.
10 * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
11 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
14 #ifndef _MONO_METADATA_W32FILE_H_
15 #define _MONO_METADATA_W32FILE_H_
17 #include <config.h>
18 #include <glib.h>
20 #include <mono/metadata/object-internals.h>
21 #include <mono/utils/mono-compiler.h>
22 #include <mono/metadata/icalls.h>
24 /* This is a copy of System.IO.FileAccess */
25 typedef enum {
26 FileAccess_Read=0x01,
27 FileAccess_Write=0x02,
28 FileAccess_ReadWrite=FileAccess_Read|FileAccess_Write
29 } MonoFileAccess;
31 /* This is a copy of System.IO.FileMode */
32 typedef enum {
33 FileMode_CreateNew=1,
34 FileMode_Create=2,
35 FileMode_Open=3,
36 FileMode_OpenOrCreate=4,
37 FileMode_Truncate=5,
38 FileMode_Append=6
39 } MonoFileMode;
41 /* This is a copy of System.IO.FileShare */
42 typedef enum {
43 FileShare_None=0x0,
44 FileShare_Read=0x01,
45 FileShare_Write=0x02,
46 FileShare_ReadWrite=FileShare_Read|FileShare_Write,
47 FileShare_Delete=0x04
48 } MonoFileShare;
50 /* This is a copy of System.IO.FileOptions */
51 typedef enum {
52 FileOptions_None = 0,
53 FileOptions_Temporary = 1, // Internal. See note in System.IO.FileOptions
54 FileOptions_Encrypted = 0x4000,
55 FileOptions_DeleteOnClose = 0x4000000,
56 FileOptions_SequentialScan = 0x8000000,
57 FileOptions_RandomAccess = 0x10000000,
58 FileOptions_Asynchronous = 0x40000000,
59 FileOptions_WriteThrough = 0x80000000
60 } MonoFileOptions;
62 /* This is a copy of System.IO.SeekOrigin */
63 typedef enum {
64 SeekOrigin_Begin=0,
65 SeekOrigin_Current=1,
66 SeekOrigin_End=2
67 } MonoSeekOrigin;
69 /* This is a copy of System.IO.MonoIOStat */
70 typedef struct _MonoIOStat {
71 gint32 attributes;
72 gint64 length;
73 gint64 creation_time;
74 gint64 last_access_time;
75 gint64 last_write_time;
76 } MonoIOStat;
78 /* This is a copy of System.IO.FileAttributes */
79 typedef enum {
80 FileAttributes_ReadOnly=0x00001,
81 FileAttributes_Hidden=0x00002,
82 FileAttributes_System=0x00004,
83 FileAttributes_Directory=0x00010,
84 FileAttributes_Archive=0x00020,
85 FileAttributes_Device=0x00040,
86 FileAttributes_Normal=0x00080,
87 FileAttributes_Temporary=0x00100,
88 FileAttributes_SparseFile=0x00200,
89 FileAttributes_ReparsePoint=0x00400,
90 FileAttributes_Compressed=0x00800,
91 FileAttributes_Offline=0x01000,
92 FileAttributes_NotContentIndexed=0x02000,
93 FileAttributes_Encrypted=0x04000,
94 FileAttributes_MonoExecutable= (int) 0x80000000
95 } MonoFileAttributes;
96 /* This is not used anymore
97 typedef struct _MonoFSAsyncResult {
98 MonoObject obj;
99 MonoObject *state;
100 MonoBoolean completed;
101 MonoBoolean done;
102 MonoException *exc;
103 MonoWaitHandle *wait_handle;
104 MonoDelegate *async_callback;
105 MonoBoolean completed_synch;
106 MonoArray *buffer;
107 gint offset;
108 gint count;
109 gint original_count;
110 gint bytes_read;
111 MonoDelegate *real_cb;
112 } MonoFSAsyncResult;
114 /* System.IO.MonoIO */
116 #if !ENABLE_NETCORE
118 ICALL_EXPORT
119 MonoBoolean
120 ves_icall_System_IO_MonoIO_CreateDirectory (const gunichar2 *path, gint32 *error);
122 ICALL_EXPORT
123 MonoBoolean
124 ves_icall_System_IO_MonoIO_RemoveDirectory (const gunichar2 *path, gint32 *error);
126 ICALL_EXPORT
127 MonoBoolean
128 ves_icall_System_IO_MonoIO_FindCloseFile (gpointer hnd);
130 ICALL_EXPORT
131 MonoBoolean
132 ves_icall_System_IO_MonoIO_SetCurrentDirectory (const gunichar2 *path,
133 gint32 *error);
134 ICALL_EXPORT
135 MonoBoolean
136 ves_icall_System_IO_MonoIO_MoveFile (const gunichar2 *path, const gunichar2 *dest,
137 gint32 *error);
138 ICALL_EXPORT
139 MonoBoolean
140 ves_icall_System_IO_MonoIO_CopyFile (const gunichar2 *path, const gunichar2 *dest,
141 MonoBoolean overwrite, gint32 *error);
142 ICALL_EXPORT
143 MonoBoolean
144 ves_icall_System_IO_MonoIO_DeleteFile (const gunichar2 *path, gint32 *error);
146 ICALL_EXPORT
147 gint32
148 ves_icall_System_IO_MonoIO_GetFileAttributes (const gunichar2 *path, gint32 *error);
150 ICALL_EXPORT
151 MonoBoolean
152 ves_icall_System_IO_MonoIO_SetFileAttributes (const gunichar2 *path, gint32 attrs,
153 gint32 *error);
154 ICALL_EXPORT
155 gint32
156 ves_icall_System_IO_MonoIO_GetFileType (gpointer handle, gint32 *error);
158 ICALL_EXPORT
159 MonoBoolean
160 ves_icall_System_IO_MonoIO_GetFileStat (const gunichar2 *path, MonoIOStat *stat,
161 gint32 *error);
162 ICALL_EXPORT
163 gpointer
164 ves_icall_System_IO_MonoIO_Open (const gunichar2 *filename, gint32 mode,
165 gint32 access_mode, gint32 share, gint32 options,
166 gint32 *error);
167 ICALL_EXPORT
168 MonoBoolean
169 ves_icall_System_IO_MonoIO_Close (gpointer handle, gint32 *error);
171 ICALL_EXPORT
172 gint64
173 ves_icall_System_IO_MonoIO_Seek (gpointer handle, gint64 offset, gint32 origin,
174 gint32 *error);
175 ICALL_EXPORT
176 MonoBoolean
177 ves_icall_System_IO_MonoIO_Flush (gpointer handle, gint32 *error);
179 ICALL_EXPORT
180 gint64
181 ves_icall_System_IO_MonoIO_GetLength (gpointer handle, gint32 *error);
183 ICALL_EXPORT
184 MonoBoolean
185 ves_icall_System_IO_MonoIO_SetLength (gpointer handle, gint64 length,
186 gint32 *error);
187 ICALL_EXPORT
188 MonoBoolean
189 ves_icall_System_IO_MonoIO_SetFileTime (gpointer handle, gint64 creation_time,
190 gint64 last_access_time,
191 gint64 last_write_time, gint32 *error);
192 ICALL_EXPORT
193 gpointer
194 ves_icall_System_IO_MonoIO_get_ConsoleOutput (void);
196 ICALL_EXPORT
197 gpointer
198 ves_icall_System_IO_MonoIO_get_ConsoleInput (void);
200 ICALL_EXPORT
201 gpointer
202 ves_icall_System_IO_MonoIO_get_ConsoleError (void);
204 ICALL_EXPORT
205 MonoBoolean
206 ves_icall_System_IO_MonoIO_CreatePipe (gpointer *read_handle, gpointer *write_handle, gint32 *error);
208 ICALL_EXPORT
209 MonoBoolean
210 ves_icall_System_IO_MonoIO_DuplicateHandle (gpointer source_process_handle, gpointer source_handle,
211 gpointer target_process_handle, gpointer *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error);
213 ICALL_EXPORT
214 gunichar2
215 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar (void);
217 ICALL_EXPORT
218 gunichar2
219 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar (void);
221 ICALL_EXPORT
222 gunichar2
223 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar (void);
225 ICALL_EXPORT
226 gunichar2
227 ves_icall_System_IO_MonoIO_get_PathSeparator (void);
229 ICALL_EXPORT
230 void ves_icall_System_IO_MonoIO_Lock (gpointer handle, gint64 position,
231 gint64 length, gint32 *error);
233 ICALL_EXPORT
234 void ves_icall_System_IO_MonoIO_Unlock (gpointer handle, gint64 position,
235 gint64 length, gint32 *error);
236 ICALL_EXPORT
237 MonoBoolean
238 ves_icall_System_IO_MonoIO_ReplaceFile (const gunichar2 *source_file_name, const gunichar2 *destination_file_name,
239 const gunichar2 *destination_backup_file_name, MonoBoolean ignore_metadata_errors,
240 gint32 *error);
242 ICALL_EXPORT
243 void
244 ves_icall_System_IO_MonoIO_DumpHandles (void);
246 #endif /* !ENABLE_NETCORE */
248 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
250 MONO_API MONO_RT_EXTERNAL_ONLY gint64
251 mono_filesize_from_path (MonoString *path);
253 extern gint64
254 mono_filesize_from_fd (int fd);
256 #endif
258 #if !defined(HOST_WIN32)
260 #define GENERIC_READ 0x80000000
261 #define GENERIC_WRITE 0x40000000
262 #define GENERIC_EXECUTE 0x20000000
263 #define GENERIC_ALL 0x10000000
265 #define FILE_SHARE_READ 0x00000001
266 #define FILE_SHARE_WRITE 0x00000002
267 #define FILE_SHARE_DELETE 0x00000004
269 #define CREATE_NEW 1
270 #define CREATE_ALWAYS 2
271 #define OPEN_EXISTING 3
272 #define OPEN_ALWAYS 4
273 #define TRUNCATE_EXISTING 5
275 #define FILE_ATTRIBUTE_READONLY 0x00000001
276 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
277 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
278 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
279 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
280 #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
281 #define FILE_ATTRIBUTE_NORMAL 0x00000080
282 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
283 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
284 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
285 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
286 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
287 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
288 #define FILE_FLAG_OPEN_NO_RECALL 0x00100000
289 #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
290 #define FILE_FLAG_POSIX_SEMANTICS 0x01000000
291 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
292 #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
293 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
294 #define FILE_FLAG_RANDOM_ACCESS 0x10000000
295 #define FILE_FLAG_NO_BUFFERING 0x20000000
296 #define FILE_FLAG_OVERLAPPED 0x40000000
297 #define FILE_FLAG_WRITE_THROUGH 0x80000000
299 #define REPLACEFILE_WRITE_THROUGH 0x00000001
300 #define REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002
302 #define MAX_PATH 260
304 #define INVALID_SET_FILE_POINTER ((guint32) 0xFFFFFFFF)
305 #define INVALID_FILE_SIZE ((guint32) 0xFFFFFFFF)
306 #define INVALID_FILE_ATTRIBUTES ((guint32) 0xFFFFFFFF)
308 #define FILE_TYPE_UNKNOWN 0x0000
309 #define FILE_TYPE_DISK 0x0001
310 #define FILE_TYPE_CHAR 0x0002
311 #define FILE_TYPE_PIPE 0x0003
312 #define FILE_TYPE_REMOTE 0x8000
314 #define FILE_BEGIN 0
315 #define FILE_CURRENT 1
316 #define FILE_END 2
318 #define DRIVE_UNKNOWN 0
319 #define DRIVE_NO_ROOT_DIR 1
320 #define DRIVE_REMOVABLE 2
321 #define DRIVE_FIXED 3
322 #define DRIVE_REMOTE 4
323 #define DRIVE_CDROM 5
324 #define DRIVE_RAMDISK 6
326 typedef struct {
327 guint16 wYear;
328 guint16 wMonth;
329 guint16 wDayOfWeek;
330 guint16 wDay;
331 guint16 wHour;
332 guint16 wMinute;
333 guint16 wSecond;
334 guint16 wMilliseconds;
335 } SYSTEMTIME;
337 typedef struct {
338 #if G_BYTE_ORDER == G_BIG_ENDIAN
339 guint32 dwHighDateTime;
340 guint32 dwLowDateTime;
341 #else
342 guint32 dwLowDateTime;
343 guint32 dwHighDateTime;
344 #endif
345 } FILETIME;
347 typedef struct {
348 guint32 dwFileAttributes;
349 FILETIME ftCreationTime;
350 FILETIME ftLastAccessTime;
351 FILETIME ftLastWriteTime;
352 guint32 nFileSizeHigh;
353 guint32 nFileSizeLow;
354 guint32 dwReserved0;
355 guint32 dwReserved1;
356 gunichar2 cFileName [MAX_PATH];
357 gunichar2 cAlternateFileName [14];
358 } WIN32_FIND_DATA;
360 #endif /* !defined(HOST_WIN32) */
362 void
363 mono_w32file_init (void);
365 void
366 mono_w32file_cleanup (void);
368 gpointer
369 mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs);
371 gboolean
372 mono_w32file_close (gpointer handle);
374 gboolean
375 mono_w32file_delete (const gunichar2 *name);
377 gboolean
378 mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread, gint32 *win32error);
380 gboolean
381 mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten, gint32 *win32error);
383 gboolean
384 mono_w32file_flush (gpointer handle);
386 gboolean
387 mono_w32file_truncate (gpointer handle);
389 guint32
390 mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method);
392 gboolean
393 mono_w32file_move (const gunichar2 *path, const gunichar2 *dest, gint32 *error);
395 gboolean
396 mono_w32file_copy (const gunichar2 *path, const gunichar2 *dest, gboolean overwrite, gint32 *error);
398 gboolean
399 mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error);
401 gboolean
402 mono_w32file_replace (const gunichar2 *destination_file_name, const gunichar2 *source_file_name, const gunichar2 *destination_backup_file_name, guint32 flags, gint32 *error);
404 gboolean
405 mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error);
407 gpointer
408 mono_w32file_get_console_output (void);
410 gpointer
411 mono_w32file_get_console_error (void);
413 gpointer
414 mono_w32file_get_console_input (void);
416 gint64
417 mono_w32file_get_file_size (gpointer handle, gint32 *error);
419 gint
420 mono_w32file_get_type (gpointer handle);
422 gboolean
423 mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time);
425 gboolean
426 mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time);
428 gpointer
429 mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data);
431 gboolean
432 mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data);
434 gboolean
435 mono_w32file_find_close (gpointer handle);
437 gboolean
438 mono_w32file_create_directory (const gunichar2 *name);
440 gboolean
441 mono_w32file_remove_directory (const gunichar2 *name);
443 guint32
444 mono_w32file_get_attributes (const gunichar2 *name);
446 gboolean
447 mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat);
449 gboolean
450 mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs);
452 guint32
453 mono_w32file_get_cwd (guint32 length, gunichar2 *buffer);
455 gboolean
456 mono_w32file_set_cwd (const gunichar2 *path);
458 gboolean
459 mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size);
461 gint32
462 mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf);
464 #ifndef PLATFORM_NO_DRIVEINFO
465 gboolean
466 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);
467 #endif // PLATFORM_NO_DRIVEINFO
469 gboolean
470 mono_w32file_get_file_system_type (const gunichar2 *path, gunichar2 *fsbuffer, gint fsbuffersize);
472 #endif /* _MONO_METADATA_W32FILE_H_ */