* mics.c: fix bug in _wapi_calc_timeout. It gave wrong values for
[mono.git] / mono / io-layer / io.h
1 /*
2  * io.h: File, console and find handles
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #ifndef _WAPI_IO_H_
11 #define _WAPI_IO_H_
12
13 #include <stdlib.h>
14
15 #include "mono/io-layer/wapi.h"
16 #include "mono/io-layer/timefuncs.h"
17
18 typedef struct _WapiSecurityAttributes WapiSecurityAttributes;
19
20 struct _WapiSecurityAttributes 
21 {
22         guint32 nLength;
23         gpointer lpSecurityDescriptor;
24         gboolean bInheritHandle;
25 };
26
27 typedef struct _WapiOverlapped WapiOverlapped;
28
29 struct _WapiOverlapped
30 {
31         guint32 Internal;
32         guint32 InternalHigh;
33         guint32 Offset;
34         guint32 OffsetHigh;
35         gpointer hEvent;
36 };
37
38 #define GENERIC_READ    0x80000000
39 #define GENERIC_WRITE   0x40000000
40 #define GENERIC_EXECUTE 0x20000000
41 #define GENERIC_ALL     0x10000000
42
43 #define FILE_SHARE_READ         0x00000001
44 #define FILE_SHARE_WRITE        0x00000002
45 #define FILE_SHARE_DELETE       0x00000004
46
47 #define CREATE_NEW              1
48 #define CREATE_ALWAYS           2
49 #define OPEN_EXISTING           3
50 #define OPEN_ALWAYS             4
51 #define TRUNCATE_EXISTING       5
52
53
54 #define FILE_ATTRIBUTE_READONLY                 0x00000001
55 #define FILE_ATTRIBUTE_HIDDEN                   0x00000002
56 #define FILE_ATTRIBUTE_SYSTEM                   0x00000004
57 #define FILE_ATTRIBUTE_DIRECTORY                0x00000010
58 #define FILE_ATTRIBUTE_ARCHIVE                  0x00000020
59 #define FILE_ATTRIBUTE_ENCRYPTED                0x00000040
60 #define FILE_ATTRIBUTE_NORMAL                   0x00000080
61 #define FILE_ATTRIBUTE_TEMPORARY                0x00000100
62 #define FILE_ATTRIBUTE_SPARSE_FILE              0x00000200
63 #define FILE_ATTRIBUTE_REPARSE_POINT            0x00000400
64 #define FILE_ATTRIBUTE_COMPRESSED               0x00000800
65 #define FILE_ATTRIBUTE_OFFLINE                  0x00001000
66 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED      0x00002000
67 #define FILE_FLAG_OPEN_NO_RECALL                0x00100000
68 #define FILE_FLAG_OPEN_REPARSE_POINT            0x00200000
69 #define FILE_FLAG_POSIX_SEMANTICS               0x01000000
70 #define FILE_FLAG_BACKUP_SEMANTICS              0x02000000
71 #define FILE_FLAG_DELETE_ON_CLOSE               0x04000000
72 #define FILE_FLAG_SEQUENTIAL_SCAN               0x08000000
73 #define FILE_FLAG_RANDOM_ACCESS                 0x10000000
74 #define FILE_FLAG_NO_BUFFERING                  0x20000000
75 #define FILE_FLAG_OVERLAPPED                    0x40000000
76 #define FILE_FLAG_WRITE_THROUGH                 0x80000000
77
78 #define MAX_PATH        260
79
80 typedef enum {
81         STD_INPUT_HANDLE=-10,
82         STD_OUTPUT_HANDLE=-11,
83         STD_ERROR_HANDLE=-12,
84 } WapiStdHandle;
85
86 typedef enum {
87         FILE_BEGIN=0,
88         FILE_CURRENT=1,
89         FILE_END=2,
90 } WapiSeekMethod;
91
92 typedef enum {
93         FILE_TYPE_UNKNOWN=0x0000,
94         FILE_TYPE_DISK=0x0001,
95         FILE_TYPE_CHAR=0x0002,
96         FILE_TYPE_PIPE=0x0003,
97         FILE_TYPE_REMOTE=0x8000,
98 } WapiFileType;
99
100 typedef enum {
101         GetFileExInfoStandard=0x0000,
102         GetFileExMaxInfoLevel=0x0001
103 } WapiGetFileExInfoLevels;
104
105 typedef struct 
106 {
107         guint16 wYear;
108         guint16 wMonth;
109         guint16 wDayOfWeek;
110         guint16 wDay;
111         guint16 wHour;
112         guint16 wMinute;
113         guint16 wSecond;
114         guint16 wMilliseconds;
115 } WapiSystemTime;
116
117 typedef struct
118 {
119         guint32 dwFileAttributes;
120         WapiFileTime ftCreationTime;
121         WapiFileTime ftLastAccessTime;
122         WapiFileTime ftLastWriteTime;
123         guint32 nFileSizeHigh;
124         guint32 nFileSizeLow;
125         guint32 dwReserved0;
126         guint32 dwReserved1;
127         gunichar2 cFileName [MAX_PATH];
128         gunichar2 cAlternateFileName [14];
129 } WapiFindData;
130
131 typedef struct
132 {
133         guint32 dwFileAttributes;
134         WapiFileTime ftCreationTime;
135         WapiFileTime ftLastAccessTime;
136         WapiFileTime ftLastWriteTime;
137         guint32 nFileSizeHigh;
138         guint32 nFileSizeLow;
139 } WapiFileAttributesData;
140
141 #define INVALID_SET_FILE_POINTER ((guint32)-1)
142 #define INVALID_FILE_SIZE ((guint32)0xFFFFFFFF)
143 #define INVALID_FILE_ATTRIBUTES ((guint32)-1)
144
145 extern gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
146                            guint32 sharemode,
147                            WapiSecurityAttributes *security,
148                            guint32 createmode,
149                            guint32 attrs, gpointer tmplate);
150 extern gboolean DeleteFile(const gunichar2 *name);
151 extern gpointer GetStdHandle(WapiStdHandle stdhandle);
152 extern gboolean ReadFile(gpointer handle, gpointer buffer, guint32 numbytes,
153                          guint32 *bytesread, WapiOverlapped *overlapped);
154 extern gboolean WriteFile(gpointer handle, gconstpointer buffer,
155                           guint32 numbytes, guint32 *byteswritten,
156                           WapiOverlapped *overlapped);
157 extern gboolean FlushFileBuffers(gpointer handle);
158 extern gboolean SetEndOfFile(gpointer handle);
159 extern guint32 SetFilePointer(gpointer handle, gint32 movedistance,
160                               gint32 *highmovedistance, WapiSeekMethod method);
161 extern WapiFileType GetFileType(gpointer handle);
162 extern guint32 GetFileSize(gpointer handle, guint32 *highsize);
163 extern gboolean GetFileTime(gpointer handle, WapiFileTime *create_time,
164                             WapiFileTime *last_access,
165                             WapiFileTime *last_write);
166 extern gboolean SetFileTime(gpointer handle, const WapiFileTime *create_time,
167                             const WapiFileTime *last_access,
168                             const WapiFileTime *last_write);
169 extern gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
170                                      WapiSystemTime *system_time);
171 extern gpointer FindFirstFile (const gunichar2 *pattern,
172                                WapiFindData *find_data);
173 extern gboolean FindNextFile (gpointer handle, WapiFindData *find_data);
174 extern gboolean FindClose (gpointer handle);
175 extern gboolean CreateDirectory (const gunichar2 *name,
176                                  WapiSecurityAttributes *security);
177 extern gboolean RemoveDirectory (const gunichar2 *name);
178 extern gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name);
179 extern gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name,
180                           gboolean fail_if_exists);
181 extern guint32 GetFileAttributes (const gunichar2 *name);
182 extern gboolean GetFileAttributesEx (const gunichar2 *name,
183                                      WapiGetFileExInfoLevels level,
184                                      gpointer info);
185 extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs);
186 extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer);
187 extern gboolean SetCurrentDirectory (const gunichar2 *path);
188 extern gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe,
189                             WapiSecurityAttributes *security, guint32 size);
190 extern guint32 GetTempPath (guint32 len, gunichar2 *buf);
191
192 #endif /* _WAPI_IO_H_ */