]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/AIO/aio_win32.cc
Removed execute bit from various non-executable source files
[thirdparty/squid.git] / src / DiskIO / AIO / aio_win32.cc
1
2 /*
3 * $Id: aio_win32.cc,v 1.3 2007/04/28 22:26:40 hno Exp $
4 *
5 * DEBUG: section 81 aio_xxx() POSIX emulation on Windows
6 * AUTHOR: Guido Serassio <serassio@squid-cache.org>
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #include "squid.h"
37 #include "comm.h"
38 #include "aio_win32.h"
39
40 #ifdef _SQUID_WIN32_
41 VOID CALLBACK IoCompletionRoutine(DWORD dwErrorCode,
42 DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped)
43 {
44
45 struct aiocb *aiocbp = (struct aiocb *) lpOverlapped->hEvent;
46
47 aiocbp->aio_sigevent.sigev_notify = dwErrorCode;
48 aiocbp->aio_sigevent.sigev_signo = dwNumberOfBytesTransfered;
49 debugs(81, 7, "AIO operation complete: errorcode=" << dwErrorCode << " nbytes=" << dwNumberOfBytesTransfered);
50 xfree(lpOverlapped);
51 }
52
53
54 int aio_read(struct aiocb *aiocbp)
55 {
56 LPOVERLAPPED Overlapped;
57 BOOL IoOperationStatus;
58
59 /* Allocate an overlapped structure. */
60 Overlapped = (LPOVERLAPPED) xcalloc(1, sizeof(OVERLAPPED));
61
62 if (!Overlapped)
63 {
64 errno = ENOMEM;
65 return -1;
66 }
67
68 #if _FILE_OFFSET_BITS==64
69 #ifdef __GNUC__
70 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000LL);
71
72 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000LL);
73
74 #else
75
76 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000);
77
78 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000);
79
80 #endif
81 #else
82
83 Overlapped->Offset = aiocbp->aio_offset;
84
85 Overlapped->OffsetHigh = 0;
86
87 #endif
88
89 Overlapped->hEvent = aiocbp;
90
91 aiocbp->aio_sigevent.sigev_notify = EINPROGRESS;
92
93 aiocbp->aio_sigevent.sigev_signo = -1;
94
95 IoOperationStatus = ReadFileEx((HANDLE)_get_osfhandle(aiocbp->aio_fildes),
96 aiocbp->aio_buf,
97 aiocbp->aio_nbytes,
98 Overlapped,
99 IoCompletionRoutine);
100
101 /* Test to see if the I/O was queued successfully. */
102 if (!IoOperationStatus)
103 {
104 errno = GetLastError();
105 debugs(81,1, "aio_read: GetLastError=" << errno );
106 return -1;
107 }
108
109 /* The I/O queued successfully. Go back into the
110 alertable wait for I/O completion or for
111 more I/O requests. */
112 return 0;
113 }
114
115
116 int aio_read64(struct aiocb64 *aiocbp)
117 {
118 LPOVERLAPPED Overlapped;
119 BOOL IoOperationStatus;
120
121 /* Allocate an overlapped structure. */
122 Overlapped = (LPOVERLAPPED) xcalloc(1, sizeof(OVERLAPPED));
123
124 if (!Overlapped)
125 {
126 errno = ENOMEM;
127 return -1;
128 }
129
130 #ifdef __GNUC__
131 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000LL);
132
133 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000LL);
134
135 #else
136
137 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000);
138
139 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000);
140
141 #endif
142
143 Overlapped->hEvent = aiocbp;
144
145 aiocbp->aio_sigevent.sigev_notify = EINPROGRESS;
146
147 aiocbp->aio_sigevent.sigev_signo = -1;
148
149 IoOperationStatus = ReadFileEx((HANDLE)_get_osfhandle(aiocbp->aio_fildes),
150 aiocbp->aio_buf,
151 aiocbp->aio_nbytes,
152 Overlapped,
153 IoCompletionRoutine);
154
155 /* Test to see if the I/O was queued successfully. */
156 if (!IoOperationStatus)
157 {
158 errno = GetLastError();
159 debugs(81, 1, "aio_read: GetLastError=" << errno );
160 return -1;
161 }
162
163 /* The I/O queued successfully. Go back into the
164 alertable wait for I/O completion or for
165 more I/O requests. */
166 return 0;
167 }
168
169
170 int aio_write(struct aiocb *aiocbp)
171 {
172 LPOVERLAPPED Overlapped;
173 BOOL IoOperationStatus;
174
175 /* Allocate an overlapped structure. */
176 Overlapped = (LPOVERLAPPED) xcalloc(1, sizeof(OVERLAPPED));
177
178 if (!Overlapped)
179 {
180 errno = ENOMEM;
181 return -1;
182 }
183
184 #if _FILE_OFFSET_BITS==64
185 #ifdef __GNUC__
186 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000LL);
187
188 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000LL);
189
190 #else
191
192 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000);
193
194 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000);
195
196 #endif
197 #else
198
199 Overlapped->Offset = aiocbp->aio_offset;
200
201 Overlapped->OffsetHigh = 0;
202
203 #endif
204
205 Overlapped->hEvent = aiocbp;
206
207 aiocbp->aio_sigevent.sigev_notify = EINPROGRESS;
208
209 aiocbp->aio_sigevent.sigev_signo = -1;
210
211 IoOperationStatus = WriteFileEx((HANDLE)_get_osfhandle(aiocbp->aio_fildes),
212 aiocbp->aio_buf,
213 aiocbp->aio_nbytes,
214 Overlapped,
215 IoCompletionRoutine);
216
217 /* Test to see if the I/O was queued successfully. */
218 if (!IoOperationStatus)
219 {
220 errno = GetLastError();
221 debugs(81, 1, "aio_write: GetLastError=" << errno );
222 return -1;
223 }
224
225 /* The I/O queued successfully. Go back into the
226 alertable wait for I/O completion or for
227 more I/O requests. */
228 return 0;
229 }
230
231
232 int aio_write64(struct aiocb64 *aiocbp)
233 {
234 LPOVERLAPPED Overlapped;
235 BOOL IoOperationStatus;
236
237 /* Allocate an overlapped structure. */
238 Overlapped = (LPOVERLAPPED) xcalloc(1, sizeof(OVERLAPPED));
239
240 if (!Overlapped)
241 {
242 errno = ENOMEM;
243 return -1;
244 }
245
246 #ifdef __GNUC__
247 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000LL);
248
249 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000LL);
250
251 #else
252
253 Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000);
254
255 Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000);
256
257 #endif
258
259 Overlapped->hEvent = aiocbp;
260
261 aiocbp->aio_sigevent.sigev_notify = EINPROGRESS;
262
263 aiocbp->aio_sigevent.sigev_signo = -1;
264
265 IoOperationStatus = WriteFileEx((HANDLE)_get_osfhandle(aiocbp->aio_fildes),
266 aiocbp->aio_buf,
267 aiocbp->aio_nbytes,
268 Overlapped,
269 IoCompletionRoutine);
270
271 /* Test to see if the I/O was queued successfully. */
272 if (!IoOperationStatus)
273 {
274 errno = GetLastError();
275 debugs(81, 1, "aio_write: GetLastError=" << errno );
276 return -1;
277 }
278
279 /* The I/O queued successfully. Go back into the
280 alertable wait for I/O completion or for
281 more I/O requests. */
282 return 0;
283 }
284
285
286 int aio_error(const struct aiocb * aiocbp)
287 {
288 return aiocbp->aio_sigevent.sigev_notify;
289 }
290
291
292 int aio_error64(const struct aiocb64 * aiocbp)
293 {
294 return aiocbp->aio_sigevent.sigev_notify;
295 }
296
297
298 int aio_open(const char *path, int mode)
299 {
300 HANDLE hndl;
301 DWORD dwCreationDisposition;
302 DWORD dwDesiredAccess;
303 int fd;
304
305 if (mode & O_WRONLY)
306 mode |= O_APPEND;
307
308 mode |= O_BINARY;
309
310 errno = 0;
311
312 if (mode & O_WRONLY)
313 dwDesiredAccess = GENERIC_WRITE;
314 else
315 dwDesiredAccess = (mode & O_RDONLY) ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE;
316
317 if (mode & O_TRUNC)
318 dwCreationDisposition = CREATE_ALWAYS;
319 else
320 dwCreationDisposition = (mode & O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING;
321
322 if ((hndl = CreateFile(path, /* file name */
323 dwDesiredAccess, /* access mode */
324 0, /* share mode */
325 NULL, /* SD */
326 dwCreationDisposition, /* how to create */
327 FILE_FLAG_OVERLAPPED, /* file attributes */
328 NULL /* handle to template file */
329 )) != INVALID_HANDLE_VALUE) {
330 statCounter.syscalls.disk.opens++;
331 fd = _open_osfhandle((long) hndl, 0);
332 commSetCloseOnExec(fd);
333 fd_open(fd, FD_FILE, path);
334 } else {
335 errno = GetLastError();
336 fd = DISK_ERROR;
337 }
338
339 return fd;
340 }
341
342
343 void aio_close(int fd)
344 {
345 CloseHandle((HANDLE)_get_osfhandle(fd));
346 fd_close(fd);
347 statCounter.syscalls.disk.closes++;
348 }
349
350
351 ssize_t aio_return(struct aiocb * aiocbp)
352 {
353 return aiocbp->aio_sigevent.sigev_signo;
354 }
355
356
357 ssize_t aio_return64(struct aiocb64 * aiocbp)
358
359 {
360 return aiocbp->aio_sigevent.sigev_signo;
361 }
362 #endif /* _SQUID_WIN32_ */