2005-06-05 Peter Bartok <pbartok@novell.com>
[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         gpointer handle1;
37         gpointer handle2;
38 };
39
40 typedef void (*WapiOverlappedCB) (guint32 error, guint32 numbytes,
41                                   WapiOverlapped *overlapped);
42
43 #define GENERIC_READ    0x80000000
44 #define GENERIC_WRITE   0x40000000
45 #define GENERIC_EXECUTE 0x20000000
46 #define GENERIC_ALL     0x10000000
47
48 #define FILE_SHARE_READ         0x00000001
49 #define FILE_SHARE_WRITE        0x00000002
50 #define FILE_SHARE_DELETE       0x00000004
51
52 #define CREATE_NEW              1
53 #define CREATE_ALWAYS           2
54 #define OPEN_EXISTING           3
55 #define OPEN_ALWAYS             4
56 #define TRUNCATE_EXISTING       5
57
58
59 #define FILE_ATTRIBUTE_READONLY                 0x00000001
60 #define FILE_ATTRIBUTE_HIDDEN                   0x00000002
61 #define FILE_ATTRIBUTE_SYSTEM                   0x00000004
62 #define FILE_ATTRIBUTE_DIRECTORY                0x00000010
63 #define FILE_ATTRIBUTE_ARCHIVE                  0x00000020
64 #define FILE_ATTRIBUTE_ENCRYPTED                0x00000040
65 #define FILE_ATTRIBUTE_NORMAL                   0x00000080
66 #define FILE_ATTRIBUTE_TEMPORARY                0x00000100
67 #define FILE_ATTRIBUTE_SPARSE_FILE              0x00000200
68 #define FILE_ATTRIBUTE_REPARSE_POINT            0x00000400
69 #define FILE_ATTRIBUTE_COMPRESSED               0x00000800
70 #define FILE_ATTRIBUTE_OFFLINE                  0x00001000
71 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED      0x00002000
72 #define FILE_FLAG_OPEN_NO_RECALL                0x00100000
73 #define FILE_FLAG_OPEN_REPARSE_POINT            0x00200000
74 #define FILE_FLAG_POSIX_SEMANTICS               0x01000000
75 #define FILE_FLAG_BACKUP_SEMANTICS              0x02000000
76 #define FILE_FLAG_DELETE_ON_CLOSE               0x04000000
77 #define FILE_FLAG_SEQUENTIAL_SCAN               0x08000000
78 #define FILE_FLAG_RANDOM_ACCESS                 0x10000000
79 #define FILE_FLAG_NO_BUFFERING                  0x20000000
80 #define FILE_FLAG_OVERLAPPED                    0x40000000
81 #define FILE_FLAG_WRITE_THROUGH                 0x80000000
82
83 #define MAX_PATH        260
84
85 typedef enum {
86         STD_INPUT_HANDLE=-10,
87         STD_OUTPUT_HANDLE=-11,
88         STD_ERROR_HANDLE=-12
89 } WapiStdHandle;
90
91 typedef enum {
92         FILE_BEGIN=0,
93         FILE_CURRENT=1,
94         FILE_END=2
95 } WapiSeekMethod;
96
97 typedef enum {
98         FILE_TYPE_UNKNOWN=0x0000,
99         FILE_TYPE_DISK=0x0001,
100         FILE_TYPE_CHAR=0x0002,
101         FILE_TYPE_PIPE=0x0003,
102         FILE_TYPE_REMOTE=0x8000
103 } WapiFileType;
104
105 typedef enum {
106         GetFileExInfoStandard=0x0000,
107         GetFileExMaxInfoLevel=0x0001
108 } WapiGetFileExInfoLevels;
109
110 typedef struct 
111 {
112         guint16 wYear;
113         guint16 wMonth;
114         guint16 wDayOfWeek;
115         guint16 wDay;
116         guint16 wHour;
117         guint16 wMinute;
118         guint16 wSecond;
119         guint16 wMilliseconds;
120 } WapiSystemTime;
121
122 typedef struct
123 {
124         guint32 dwFileAttributes;
125         WapiFileTime ftCreationTime;
126         WapiFileTime ftLastAccessTime;
127         WapiFileTime ftLastWriteTime;
128         guint32 nFileSizeHigh;
129         guint32 nFileSizeLow;
130         guint32 dwReserved0;
131         guint32 dwReserved1;
132         gunichar2 cFileName [MAX_PATH];
133         gunichar2 cAlternateFileName [14];
134 } WapiFindData;
135
136 typedef struct
137 {
138         guint32 dwFileAttributes;
139         WapiFileTime ftCreationTime;
140         WapiFileTime ftLastAccessTime;
141         WapiFileTime ftLastWriteTime;
142         guint32 nFileSizeHigh;
143         guint32 nFileSizeLow;
144 } WapiFileAttributesData;
145
146 #define INVALID_SET_FILE_POINTER ((guint32)-1)
147 #define INVALID_FILE_SIZE ((guint32)0xFFFFFFFF)
148 #define INVALID_FILE_ATTRIBUTES ((guint32)-1)
149
150 extern gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
151                            guint32 sharemode,
152                            WapiSecurityAttributes *security,
153                            guint32 createmode,
154                            guint32 attrs, gpointer tmplate);
155 extern gboolean DeleteFile(const gunichar2 *name);
156 extern gpointer GetStdHandle(WapiStdHandle stdhandle);
157 extern gboolean ReadFile(gpointer handle, gpointer buffer, guint32 numbytes,
158                          guint32 *bytesread, WapiOverlapped *overlapped);
159 extern gboolean WriteFile(gpointer handle, gconstpointer buffer,
160                           guint32 numbytes, guint32 *byteswritten,
161                           WapiOverlapped *overlapped);
162 extern gboolean FlushFileBuffers(gpointer handle);
163 extern gboolean SetEndOfFile(gpointer handle);
164 extern guint32 SetFilePointer(gpointer handle, gint32 movedistance,
165                               gint32 *highmovedistance, WapiSeekMethod method);
166 extern WapiFileType GetFileType(gpointer handle);
167 extern guint32 GetFileSize(gpointer handle, guint32 *highsize);
168 extern gboolean GetFileTime(gpointer handle, WapiFileTime *create_time,
169                             WapiFileTime *last_access,
170                             WapiFileTime *last_write);
171 extern gboolean SetFileTime(gpointer handle, const WapiFileTime *create_time,
172                             const WapiFileTime *last_access,
173                             const WapiFileTime *last_write);
174 extern gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
175                                      WapiSystemTime *system_time);
176 extern gpointer FindFirstFile (const gunichar2 *pattern,
177                                WapiFindData *find_data);
178 extern gboolean FindNextFile (gpointer handle, WapiFindData *find_data);
179 extern gboolean FindClose (gpointer handle);
180 extern gboolean CreateDirectory (const gunichar2 *name,
181                                  WapiSecurityAttributes *security);
182 extern gboolean RemoveDirectory (const gunichar2 *name);
183 extern gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name);
184 extern gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name,
185                           gboolean fail_if_exists);
186 extern guint32 GetFileAttributes (const gunichar2 *name);
187 extern gboolean GetFileAttributesEx (const gunichar2 *name,
188                                      WapiGetFileExInfoLevels level,
189                                      gpointer info);
190 extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs);
191 extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer);
192 extern gboolean SetCurrentDirectory (const gunichar2 *path);
193 extern gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe,
194                             WapiSecurityAttributes *security, guint32 size);
195 extern guint32 GetTempPath (guint32 len, gunichar2 *buf);
196 extern gint32 GetLogicalDriveStrings (guint32 len, gunichar2 *buf);
197 extern gboolean LockFile (gpointer handle, guint32 offset_low,
198                           guint32 offset_high, guint32 length_low,
199                           guint32 length_high);
200 extern gboolean UnlockFile (gpointer handle, guint32 offset_low,
201                             guint32 offset_high, guint32 length_low,
202                             guint32 length_high);
203
204 #endif /* _WAPI_IO_H_ */