Merge pull request #4169 from evincarofautumn/fix-xmm-scanning-mac-x86
[mono.git] / mono / metadata / w32file.h
1 /*
2  * w32file.h: File IO internal calls
3  *
4  * Authors:
5  *      Dick Porter (dick@ximian.com)
6  *      Dan Lewis (dihlewis@yahoo.co.uk)
7  *
8  * (C) 2001 Ximian, Inc.
9  * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
10  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12
13 #ifndef _MONO_METADATA_W32FILE_H_
14 #define _MONO_METADATA_W32FILE_H_
15
16 #include <config.h>
17 #include <glib.h>
18
19 #include <mono/metadata/object-internals.h>
20 #include <mono/utils/mono-compiler.h>
21
22 G_BEGIN_DECLS
23
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;
30
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;
40
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;
49
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;
61
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;
68
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;
77
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;
113 */
114 /* System.IO.MonoIO */
115
116 extern MonoBoolean
117 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error);
118
119 extern MonoBoolean
120 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error);
121
122 MonoArray *
123 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
124                                                  MonoString *path_with_pattern,
125                                                  gint mask, gint attrs,
126                                                  gint32 *error);
127
128 extern gpointer
129 ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern,
130                                                 MonoString **file_name,
131                                                 gint32 *file_attr,
132                                                 gint32 *ioerror);
133
134 extern MonoBoolean
135 ves_icall_System_IO_MonoIO_FindNextFile (gpointer hnd,
136                                                 MonoString **file_name,
137                                                 gint32 *file_attr,
138                                                 gint32 *ioerror);
139
140 extern MonoBoolean
141 ves_icall_System_IO_MonoIO_FindCloseFile (gpointer hnd);
142
143 extern MonoString *
144 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
145                                       MonoString *path_with_pattern,
146                                       gint32 *result_mask,
147                                       gint32 *error,
148                                       gpointer *handle);
149 extern MonoString *
150 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_mask, gint32 *error);
151
152 extern int
153 ves_icall_System_IO_MonoIO_FindClose (gpointer handle);
154
155 extern MonoString *
156 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error);
157
158 extern MonoBoolean
159 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
160                                                 gint32 *error);
161
162 extern MonoBoolean
163 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
164                                      gint32 *error);
165
166 extern MonoBoolean
167 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
168                                      MonoBoolean overwrite, gint32 *error);
169
170 extern MonoBoolean
171 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error);
172
173 extern gint32 
174 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error);
175
176 extern MonoBoolean
177 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
178                                               gint32 *error);
179
180 extern gint32
181 ves_icall_System_IO_MonoIO_GetFileType (gpointer handle, gint32 *error);
182
183 extern MonoBoolean
184 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
185                                         gint32 *error);
186
187 extern gpointer 
188 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
189                                  gint32 access_mode, gint32 share, gint32 options,
190                                  gint32 *error);
191
192 extern MonoBoolean
193 ves_icall_System_IO_MonoIO_Close (gpointer handle, gint32 *error);
194
195 extern gint32 
196 ves_icall_System_IO_MonoIO_Read (gpointer handle, MonoArray *dest,
197                                  gint32 dest_offset, gint32 count,
198                                  gint32 *error);
199
200 extern gint32 
201 ves_icall_System_IO_MonoIO_Write (gpointer handle, MonoArray *src,
202                                   gint32 src_offset, gint32 count,
203                                   gint32 *error);
204
205 extern gint64 
206 ves_icall_System_IO_MonoIO_Seek (gpointer handle, gint64 offset, gint32 origin,
207                                  gint32 *error);
208
209 extern MonoBoolean
210 ves_icall_System_IO_MonoIO_Flush (gpointer handle, gint32 *error);
211
212 extern gint64 
213 ves_icall_System_IO_MonoIO_GetLength (gpointer handle, gint32 *error);
214
215 extern MonoBoolean
216 ves_icall_System_IO_MonoIO_SetLength (gpointer handle, gint64 length,
217                                       gint32 *error);
218
219 extern MonoBoolean
220 ves_icall_System_IO_MonoIO_SetFileTime (gpointer handle, gint64 creation_time,
221                                         gint64 last_access_time,
222                                         gint64 last_write_time, gint32 *error);
223
224 extern gpointer 
225 ves_icall_System_IO_MonoIO_get_ConsoleOutput (void);
226
227 extern gpointer 
228 ves_icall_System_IO_MonoIO_get_ConsoleInput (void);
229
230 extern gpointer 
231 ves_icall_System_IO_MonoIO_get_ConsoleError (void);
232
233 extern MonoBoolean
234 ves_icall_System_IO_MonoIO_CreatePipe (gpointer *read_handle, gpointer *write_handle, gint32 *error);
235
236 extern MonoBoolean
237 ves_icall_System_IO_MonoIO_DuplicateHandle (gpointer source_process_handle, gpointer source_handle,
238                 gpointer target_process_handle, gpointer *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error);
239
240 extern gunichar2 
241 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar (void);
242
243 extern gunichar2 
244 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar (void);
245
246 extern gunichar2 
247 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar (void);
248
249 extern gunichar2 
250 ves_icall_System_IO_MonoIO_get_PathSeparator (void);
251
252 extern MonoArray *
253 ves_icall_System_IO_MonoIO_get_InvalidPathChars (void);
254
255 extern void ves_icall_System_IO_MonoIO_Lock (gpointer handle, gint64 position,
256                                              gint64 length, gint32 *error);
257 extern void ves_icall_System_IO_MonoIO_Unlock (gpointer handle, gint64 position,
258                                                gint64 length, gint32 *error);
259
260 extern MonoBoolean
261 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
262                                         MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
263                                         gint32 *error);
264
265 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
266
267 MONO_RT_EXTERNAL_ONLY
268 extern gint64
269 mono_filesize_from_path (MonoString *path);
270
271 extern gint64
272 mono_filesize_from_fd (int fd);
273
274 #endif
275
276 void
277 ves_icall_System_IO_MonoIO_DumpHandles (void);
278
279 #if !defined(HOST_WIN32)
280
281 #define GENERIC_READ    0x80000000
282 #define GENERIC_WRITE   0x40000000
283 #define GENERIC_EXECUTE 0x20000000
284 #define GENERIC_ALL     0x10000000
285
286 #define FILE_SHARE_READ   0x00000001
287 #define FILE_SHARE_WRITE  0x00000002
288 #define FILE_SHARE_DELETE 0x00000004
289
290 #define CREATE_NEW        1
291 #define CREATE_ALWAYS     2
292 #define OPEN_EXISTING     3
293 #define OPEN_ALWAYS       4
294 #define TRUNCATE_EXISTING 5
295
296 #define FILE_ATTRIBUTE_READONLY            0x00000001
297 #define FILE_ATTRIBUTE_HIDDEN              0x00000002
298 #define FILE_ATTRIBUTE_SYSTEM              0x00000004
299 #define FILE_ATTRIBUTE_DIRECTORY           0x00000010
300 #define FILE_ATTRIBUTE_ARCHIVE             0x00000020
301 #define FILE_ATTRIBUTE_ENCRYPTED           0x00000040
302 #define FILE_ATTRIBUTE_NORMAL              0x00000080
303 #define FILE_ATTRIBUTE_TEMPORARY           0x00000100
304 #define FILE_ATTRIBUTE_SPARSE_FILE         0x00000200
305 #define FILE_ATTRIBUTE_REPARSE_POINT       0x00000400
306 #define FILE_ATTRIBUTE_COMPRESSED          0x00000800
307 #define FILE_ATTRIBUTE_OFFLINE             0x00001000
308 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
309 #define FILE_FLAG_OPEN_NO_RECALL           0x00100000
310 #define FILE_FLAG_OPEN_REPARSE_POINT       0x00200000
311 #define FILE_FLAG_POSIX_SEMANTICS          0x01000000
312 #define FILE_FLAG_BACKUP_SEMANTICS         0x02000000
313 #define FILE_FLAG_DELETE_ON_CLOSE          0x04000000
314 #define FILE_FLAG_SEQUENTIAL_SCAN          0x08000000
315 #define FILE_FLAG_RANDOM_ACCESS            0x10000000
316 #define FILE_FLAG_NO_BUFFERING             0x20000000
317 #define FILE_FLAG_OVERLAPPED               0x40000000
318 #define FILE_FLAG_WRITE_THROUGH            0x80000000
319
320 #define REPLACEFILE_WRITE_THROUGH       0x00000001
321 #define REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002
322
323 #define MAX_PATH 260
324
325 #define INVALID_SET_FILE_POINTER ((guint32) 0xFFFFFFFF)
326 #define INVALID_FILE_SIZE        ((guint32) 0xFFFFFFFF)
327 #define INVALID_FILE_ATTRIBUTES  ((guint32) 0xFFFFFFFF)
328
329 #define FILE_TYPE_UNKNOWN 0x0000
330 #define FILE_TYPE_DISK    0x0001
331 #define FILE_TYPE_CHAR    0x0002
332 #define FILE_TYPE_PIPE    0x0003
333 #define FILE_TYPE_REMOTE  0x8000
334
335 #define FILE_BEGIN   0
336 #define FILE_CURRENT 1
337 #define FILE_END     2
338
339 #define DRIVE_UNKNOWN     0
340 #define DRIVE_NO_ROOT_DIR 1
341 #define DRIVE_REMOVABLE   2
342 #define DRIVE_FIXED       3
343 #define DRIVE_REMOTE      4
344 #define DRIVE_CDROM       5
345 #define DRIVE_RAMDISK     6
346
347 typedef struct {
348         guint16 wYear;
349         guint16 wMonth;
350         guint16 wDayOfWeek;
351         guint16 wDay;
352         guint16 wHour;
353         guint16 wMinute;
354         guint16 wSecond;
355         guint16 wMilliseconds;
356 } SYSTEMTIME;
357
358 typedef struct {
359 #if G_BYTE_ORDER == G_BIG_ENDIAN
360         guint32 dwHighDateTime;
361         guint32 dwLowDateTime;
362 #else
363         guint32 dwLowDateTime;
364         guint32 dwHighDateTime;
365 #endif
366 } FILETIME;
367
368 typedef struct {
369         guint32 dwFileAttributes;
370         FILETIME ftCreationTime;
371         FILETIME ftLastAccessTime;
372         FILETIME ftLastWriteTime;
373         guint32 nFileSizeHigh;
374         guint32 nFileSizeLow;
375         guint32 dwReserved0;
376         guint32 dwReserved1;
377         gunichar2 cFileName [MAX_PATH];
378         gunichar2 cAlternateFileName [14];
379 } WIN32_FIND_DATA;
380
381 #endif /* !defined(HOST_WIN32) */
382
383 void
384 mono_w32file_init (void);
385
386 void
387 mono_w32file_cleanup (void);
388
389 gpointer
390 mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs);
391
392 gboolean
393 mono_w32file_close (gpointer handle);
394
395 gboolean
396 mono_w32file_delete (const gunichar2 *name);
397
398 gboolean
399 mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread);
400
401 gboolean
402 mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten);
403
404 gboolean
405 mono_w32file_flush (gpointer handle);
406
407 gboolean
408 mono_w32file_truncate (gpointer handle);
409
410 guint32
411 mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method);
412
413 gboolean
414 mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error);
415
416 gboolean
417 mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error);
418
419 gboolean
420 mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error);
421
422 gboolean
423 mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error);
424
425 gboolean
426 mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error);
427
428 gpointer
429 mono_w32file_get_console_output (void);
430
431 gpointer
432 mono_w32file_get_console_error (void);
433
434 gpointer
435 mono_w32file_get_console_input (void);
436
437 gint64
438 mono_w32file_get_file_size (gpointer handle, gint32 *error);
439
440 gint
441 mono_w32file_get_type (gpointer handle);
442
443 gboolean
444 mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time);
445
446 gboolean
447 mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time);
448
449 gboolean
450 mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time);
451
452 gpointer
453 mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data);
454
455 gboolean
456 mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data);
457
458 gboolean
459 mono_w32file_find_close (gpointer handle);
460
461 gboolean
462 mono_w32file_create_directory (const gunichar2 *name);
463
464 gboolean
465 mono_w32file_remove_directory (const gunichar2 *name);
466
467 guint32
468 mono_w32file_get_attributes (const gunichar2 *name);
469
470 gboolean
471 mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat);
472
473 gboolean
474 mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs);
475
476 guint32
477 mono_w32file_get_cwd (guint32 length, gunichar2 *buffer);
478
479 gboolean
480 mono_w32file_set_cwd (const gunichar2 *path);
481
482 gboolean
483 mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size);
484
485 gint32
486 mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf);
487
488 gboolean
489 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);
490
491 guint32
492 mono_w32file_get_drive_type (const gunichar2 *root_path_name);
493
494 gboolean
495 mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize);
496
497 G_END_DECLS
498
499 #endif /* _MONO_METADATA_W32FILE_H_ */