3 * File IO internal calls
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_
20 #include <mono/metadata/object-internals.h>
21 #include <mono/utils/mono-compiler.h>
25 /* This is a copy of System.IO.FileAccess */
28 FileAccess_Write=0x02,
29 FileAccess_ReadWrite=FileAccess_Read|FileAccess_Write
32 /* This is a copy of System.IO.FileMode */
37 FileMode_OpenOrCreate=4,
42 /* This is a copy of System.IO.FileShare */
47 FileShare_ReadWrite=FileShare_Read|FileShare_Write,
51 /* This is a copy of System.IO.FileOptions */
54 FileOptions_Temporary = 1, // Internal. See note in System.IO.FileOptions
55 FileOptions_Encrypted = 0x4000,
56 FileOptions_DeleteOnClose = 0x4000000,
57 FileOptions_SequentialScan = 0x8000000,
58 FileOptions_RandomAccess = 0x10000000,
59 FileOptions_Asynchronous = 0x40000000,
60 FileOptions_WriteThrough = 0x80000000
63 /* This is a copy of System.IO.SeekOrigin */
70 /* This is a copy of System.IO.MonoIOStat */
71 typedef struct _MonoIOStat {
75 gint64 last_access_time;
76 gint64 last_write_time;
79 /* This is a copy of System.IO.FileAttributes */
81 FileAttributes_ReadOnly=0x00001,
82 FileAttributes_Hidden=0x00002,
83 FileAttributes_System=0x00004,
84 FileAttributes_Directory=0x00010,
85 FileAttributes_Archive=0x00020,
86 FileAttributes_Device=0x00040,
87 FileAttributes_Normal=0x00080,
88 FileAttributes_Temporary=0x00100,
89 FileAttributes_SparseFile=0x00200,
90 FileAttributes_ReparsePoint=0x00400,
91 FileAttributes_Compressed=0x00800,
92 FileAttributes_Offline=0x01000,
93 FileAttributes_NotContentIndexed=0x02000,
94 FileAttributes_Encrypted=0x04000,
95 FileAttributes_MonoExecutable= (int) 0x80000000
97 /* This is not used anymore
98 typedef struct _MonoFSAsyncResult {
101 MonoBoolean completed;
104 MonoWaitHandle *wait_handle;
105 MonoDelegate *async_callback;
106 MonoBoolean completed_synch;
112 MonoDelegate *real_cb;
115 /* System.IO.MonoIO */
118 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error);
121 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error);
124 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
125 MonoString *path_with_pattern,
126 gint mask, gint attrs,
130 ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern,
131 MonoString **file_name,
136 ves_icall_System_IO_MonoIO_FindNextFile (gpointer hnd,
137 MonoString **file_name,
142 ves_icall_System_IO_MonoIO_FindCloseFile (gpointer hnd);
145 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
146 MonoString *path_with_pattern,
151 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_mask, gint32 *error);
154 ves_icall_System_IO_MonoIO_FindClose (gpointer handle);
157 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error);
160 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
164 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
168 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
169 MonoBoolean overwrite, gint32 *error);
172 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error);
175 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error);
178 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
182 ves_icall_System_IO_MonoIO_GetFileType (gpointer handle, gint32 *error);
185 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
189 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
190 gint32 access_mode, gint32 share, gint32 options,
194 ves_icall_System_IO_MonoIO_Close (gpointer handle, gint32 *error);
197 ves_icall_System_IO_MonoIO_Read (gpointer handle, MonoArray *dest,
198 gint32 dest_offset, gint32 count,
202 ves_icall_System_IO_MonoIO_Write (gpointer handle, MonoArray *src,
203 gint32 src_offset, gint32 count,
207 ves_icall_System_IO_MonoIO_Seek (gpointer handle, gint64 offset, gint32 origin,
211 ves_icall_System_IO_MonoIO_Flush (gpointer handle, gint32 *error);
214 ves_icall_System_IO_MonoIO_GetLength (gpointer handle, gint32 *error);
217 ves_icall_System_IO_MonoIO_SetLength (gpointer handle, gint64 length,
221 ves_icall_System_IO_MonoIO_SetFileTime (gpointer handle, gint64 creation_time,
222 gint64 last_access_time,
223 gint64 last_write_time, gint32 *error);
226 ves_icall_System_IO_MonoIO_get_ConsoleOutput (void);
229 ves_icall_System_IO_MonoIO_get_ConsoleInput (void);
232 ves_icall_System_IO_MonoIO_get_ConsoleError (void);
235 ves_icall_System_IO_MonoIO_CreatePipe (gpointer *read_handle, gpointer *write_handle, gint32 *error);
238 ves_icall_System_IO_MonoIO_DuplicateHandle (gpointer source_process_handle, gpointer source_handle,
239 gpointer target_process_handle, gpointer *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error);
242 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar (void);
245 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar (void);
248 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar (void);
251 ves_icall_System_IO_MonoIO_get_PathSeparator (void);
254 ves_icall_System_IO_MonoIO_get_InvalidPathChars (void);
256 extern void ves_icall_System_IO_MonoIO_Lock (gpointer handle, gint64 position,
257 gint64 length, gint32 *error);
258 extern void ves_icall_System_IO_MonoIO_Unlock (gpointer handle, gint64 position,
259 gint64 length, gint32 *error);
262 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
263 MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
266 #if defined (TARGET_IOS) || defined (TARGET_ANDROID)
268 MONO_RT_EXTERNAL_ONLY
270 mono_filesize_from_path (MonoString *path);
273 mono_filesize_from_fd (int fd);
278 ves_icall_System_IO_MonoIO_DumpHandles (void);
280 #if !defined(HOST_WIN32)
282 #define GENERIC_READ 0x80000000
283 #define GENERIC_WRITE 0x40000000
284 #define GENERIC_EXECUTE 0x20000000
285 #define GENERIC_ALL 0x10000000
287 #define FILE_SHARE_READ 0x00000001
288 #define FILE_SHARE_WRITE 0x00000002
289 #define FILE_SHARE_DELETE 0x00000004
292 #define CREATE_ALWAYS 2
293 #define OPEN_EXISTING 3
294 #define OPEN_ALWAYS 4
295 #define TRUNCATE_EXISTING 5
297 #define FILE_ATTRIBUTE_READONLY 0x00000001
298 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
299 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
300 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
301 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
302 #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
303 #define FILE_ATTRIBUTE_NORMAL 0x00000080
304 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
305 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
306 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
307 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
308 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
309 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
310 #define FILE_FLAG_OPEN_NO_RECALL 0x00100000
311 #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
312 #define FILE_FLAG_POSIX_SEMANTICS 0x01000000
313 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
314 #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
315 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
316 #define FILE_FLAG_RANDOM_ACCESS 0x10000000
317 #define FILE_FLAG_NO_BUFFERING 0x20000000
318 #define FILE_FLAG_OVERLAPPED 0x40000000
319 #define FILE_FLAG_WRITE_THROUGH 0x80000000
321 #define REPLACEFILE_WRITE_THROUGH 0x00000001
322 #define REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002
326 #define INVALID_SET_FILE_POINTER ((guint32) 0xFFFFFFFF)
327 #define INVALID_FILE_SIZE ((guint32) 0xFFFFFFFF)
328 #define INVALID_FILE_ATTRIBUTES ((guint32) 0xFFFFFFFF)
330 #define FILE_TYPE_UNKNOWN 0x0000
331 #define FILE_TYPE_DISK 0x0001
332 #define FILE_TYPE_CHAR 0x0002
333 #define FILE_TYPE_PIPE 0x0003
334 #define FILE_TYPE_REMOTE 0x8000
337 #define FILE_CURRENT 1
340 #define DRIVE_UNKNOWN 0
341 #define DRIVE_NO_ROOT_DIR 1
342 #define DRIVE_REMOVABLE 2
343 #define DRIVE_FIXED 3
344 #define DRIVE_REMOTE 4
345 #define DRIVE_CDROM 5
346 #define DRIVE_RAMDISK 6
356 guint16 wMilliseconds;
360 #if G_BYTE_ORDER == G_BIG_ENDIAN
361 guint32 dwHighDateTime;
362 guint32 dwLowDateTime;
364 guint32 dwLowDateTime;
365 guint32 dwHighDateTime;
370 guint32 dwFileAttributes;
371 FILETIME ftCreationTime;
372 FILETIME ftLastAccessTime;
373 FILETIME ftLastWriteTime;
374 guint32 nFileSizeHigh;
375 guint32 nFileSizeLow;
378 gunichar2 cFileName [MAX_PATH];
379 gunichar2 cAlternateFileName [14];
382 #endif /* !defined(HOST_WIN32) */
385 mono_w32file_init (void);
388 mono_w32file_cleanup (void);
391 mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs);
394 mono_w32file_close (gpointer handle);
397 mono_w32file_delete (const gunichar2 *name);
400 mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread);
403 mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten);
406 mono_w32file_flush (gpointer handle);
409 mono_w32file_truncate (gpointer handle);
412 mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method);
415 mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error);
418 mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32 *error);
421 mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *error);
424 mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName, gunichar2 *destinationBackupFileName, guint32 flags, gint32 *error);
427 mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *error);
430 mono_w32file_get_console_output (void);
433 mono_w32file_get_console_error (void);
436 mono_w32file_get_console_input (void);
439 mono_w32file_get_file_size (gpointer handle, gint32 *error);
442 mono_w32file_get_type (gpointer handle);
445 mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time);
448 mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time);
451 mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time);
454 mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data);
457 mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data);
460 mono_w32file_find_close (gpointer handle);
463 mono_w32file_create_directory (const gunichar2 *name);
466 mono_w32file_remove_directory (const gunichar2 *name);
469 mono_w32file_get_attributes (const gunichar2 *name);
472 mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat);
475 mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs);
478 mono_w32file_get_cwd (guint32 length, gunichar2 *buffer);
481 mono_w32file_set_cwd (const gunichar2 *path);
484 mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size);
487 mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf);
490 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);
493 mono_w32file_get_drive_type (const gunichar2 *root_path_name);
496 mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize);
500 #endif /* _MONO_METADATA_W32FILE_H_ */