[corlib] Use Directory.GetFiles/GetDirectories implementation from referencesource...
[mono.git] / mono / metadata / file-io.h
1 /*
2  * file-io.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_FILEIO_H_
14 #define _MONO_METADATA_FILEIO_H_
15
16 #include <config.h>
17 #include <glib.h>
18
19 #include <mono/metadata/object-internals.h>
20 #include <mono/io-layer/io-layer.h>
21 #include <mono/utils/mono-compiler.h>
22
23 G_BEGIN_DECLS
24
25 /* This is a copy of System.IO.FileAccess */
26 typedef enum {
27         FileAccess_Read=0x01,
28         FileAccess_Write=0x02,
29         FileAccess_ReadWrite=FileAccess_Read|FileAccess_Write
30 } MonoFileAccess;
31
32 /* This is a copy of System.IO.FileMode */
33 typedef enum {
34         FileMode_CreateNew=1,
35         FileMode_Create=2,
36         FileMode_Open=3,
37         FileMode_OpenOrCreate=4,
38         FileMode_Truncate=5,
39         FileMode_Append=6
40 } MonoFileMode;
41
42 /* This is a copy of System.IO.FileShare */
43 typedef enum {
44         FileShare_None=0x0,
45         FileShare_Read=0x01,
46         FileShare_Write=0x02,
47         FileShare_ReadWrite=FileShare_Read|FileShare_Write,
48         FileShare_Delete=0x04
49 } MonoFileShare;
50
51 /* This is a copy of System.IO.FileOptions */
52 typedef enum {
53         FileOptions_None = 0,
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
61 } MonoFileOptions;
62
63 /* This is a copy of System.IO.SeekOrigin */
64 typedef enum {
65         SeekOrigin_Begin=0,
66         SeekOrigin_Current=1,
67         SeekOrigin_End=2
68 } MonoSeekOrigin;
69
70 /* This is a copy of System.IO.MonoIOStat */
71 typedef struct _MonoIOStat {
72         gint32 attributes;
73         gint64 length;
74         gint64 creation_time;
75         gint64 last_access_time;
76         gint64 last_write_time;
77 } MonoIOStat;
78
79 /* This is a copy of System.IO.FileAttributes */
80 typedef enum {
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
96 } MonoFileAttributes;
97 /* This is not used anymore
98 typedef struct _MonoFSAsyncResult {
99         MonoObject obj;
100         MonoObject *state;
101         MonoBoolean completed;
102         MonoBoolean done;
103         MonoException *exc;
104         MonoWaitHandle *wait_handle;
105         MonoDelegate *async_callback;
106         MonoBoolean completed_synch;
107         MonoArray *buffer;
108         gint offset;
109         gint count;
110         gint original_count;
111         gint bytes_read;
112         MonoDelegate *real_cb;
113 } MonoFSAsyncResult;
114 */
115 /* System.IO.MonoIO */
116
117 extern MonoBoolean
118 ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error);
119
120 extern MonoBoolean
121 ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error);
122
123 MonoArray *
124 ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
125                                                  MonoString *path_with_pattern,
126                                                  gint mask, gint attrs,
127                                                  gint32 *error);
128
129 extern HANDLE
130 ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern,
131                                                 MonoString **file_name,
132                                                 gint32 *file_attr,
133                                                 gint32 *ioerror);
134
135 extern MonoBoolean
136 ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd,
137                                                 MonoString **file_name,
138                                                 gint32 *file_attr,
139                                                 gint32 *ioerror);
140
141 extern MonoBoolean
142 ves_icall_System_IO_MonoIO_FindCloseFile (HANDLE hnd);
143
144 extern MonoString *
145 ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
146                                       MonoString *path_with_pattern,
147                                       gint32 *result_mask,
148                                       gint32 *error,
149                                       gpointer *handle);
150 extern MonoString *
151 ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_mask, gint32 *error);
152
153 extern int
154 ves_icall_System_IO_MonoIO_FindClose (gpointer handle);
155
156 extern MonoString *
157 ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *error);
158
159 extern MonoBoolean
160 ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
161                                                 gint32 *error);
162
163 extern MonoBoolean
164 ves_icall_System_IO_MonoIO_MoveFile (MonoString *path, MonoString *dest,
165                                      gint32 *error);
166
167 extern MonoBoolean
168 ves_icall_System_IO_MonoIO_CopyFile (MonoString *path, MonoString *dest,
169                                      MonoBoolean overwrite, gint32 *error);
170
171 extern MonoBoolean
172 ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error);
173
174 extern gint32 
175 ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error);
176
177 extern MonoBoolean
178 ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
179                                               gint32 *error);
180
181 extern gint32
182 ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error);
183
184 extern MonoBoolean
185 ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
186                                         gint32 *error);
187
188 extern HANDLE 
189 ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
190                                  gint32 access_mode, gint32 share, gint32 options,
191                                  gint32 *error);
192
193 extern MonoBoolean
194 ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error);
195
196 extern gint32 
197 ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
198                                  gint32 dest_offset, gint32 count,
199                                  gint32 *error);
200
201 extern gint32 
202 ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
203                                   gint32 src_offset, gint32 count,
204                                   gint32 *error);
205
206 extern gint64 
207 ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
208                                  gint32 *error);
209
210 extern MonoBoolean
211 ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error);
212
213 extern gint64 
214 ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error);
215
216 extern MonoBoolean
217 ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
218                                       gint32 *error);
219
220 extern MonoBoolean
221 ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
222                                         gint64 last_access_time,
223                                         gint64 last_write_time, gint32 *error);
224
225 extern HANDLE 
226 ves_icall_System_IO_MonoIO_get_ConsoleOutput (void);
227
228 extern HANDLE 
229 ves_icall_System_IO_MonoIO_get_ConsoleInput (void);
230
231 extern HANDLE 
232 ves_icall_System_IO_MonoIO_get_ConsoleError (void);
233
234 extern MonoBoolean
235 ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error);
236
237 extern MonoBoolean
238 ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
239                 HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error);
240
241 extern gunichar2 
242 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar (void);
243
244 extern gunichar2 
245 ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar (void);
246
247 extern gunichar2 
248 ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar (void);
249
250 extern gunichar2 
251 ves_icall_System_IO_MonoIO_get_PathSeparator (void);
252
253 extern MonoArray *
254 ves_icall_System_IO_MonoIO_get_InvalidPathChars (void);
255
256 extern void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
257                                              gint64 length, gint32 *error);
258 extern void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
259                                                gint64 length, gint32 *error);
260
261 extern MonoBoolean
262 ves_icall_System_IO_MonoIO_ReplaceFile (MonoString *sourceFileName, MonoString *destinationFileName,
263                                         MonoString *destinationBackupFileName, MonoBoolean ignoreMetadataErrors,
264                                         gint32 *error);
265
266 MONO_RT_EXTERNAL_ONLY
267 extern gint64
268 mono_filesize_from_path (MonoString *path);
269
270 extern gint64
271 mono_filesize_from_fd (int fd);
272
273 void
274 ves_icall_System_IO_MonoIO_DumpHandles (void);
275
276 G_END_DECLS
277
278 #endif /* _MONO_METADATA_FILEIO_H_ */