Wait for the object multiple times until TIMEOUT is met.
[wine/multimedia.git] / dlls / ntdll / file.c
blobe0703f9dda8416c8d302152e7d2dcca77b32a283
1 /*
2 * Copyright 1999, 2000 Juergen Schmied
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "config.h"
20 #include "wine/port.h"
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <assert.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #ifdef HAVE_SYS_ERRNO_H
31 #include <sys/errno.h>
32 #endif
33 #ifdef HAVE_LINUX_MAJOR_H
34 # include <linux/major.h>
35 #endif
36 #ifdef HAVE_SYS_STATVFS_H
37 # include <sys/statvfs.h>
38 #endif
39 #ifdef HAVE_SYS_PARAM_H
40 # include <sys/param.h>
41 #endif
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
44 #endif
45 #ifdef HAVE_UTIME_H
46 # include <utime.h>
47 #endif
48 #ifdef STATFS_DEFINED_BY_SYS_VFS
49 # include <sys/vfs.h>
50 #else
51 # ifdef STATFS_DEFINED_BY_SYS_MOUNT
52 # include <sys/mount.h>
53 # else
54 # ifdef STATFS_DEFINED_BY_SYS_STATFS
55 # include <sys/statfs.h>
56 # endif
57 # endif
58 #endif
60 #ifdef __APPLE__
61 # include <IOKit/IOKitLib.h>
62 # include <CoreFoundation/CFNumber.h> /* for kCFBooleanTrue, kCFBooleanFalse */
63 # include <paths.h>
64 #endif
66 #define NONAMELESSUNION
67 #define NONAMELESSSTRUCT
68 #include "wine/unicode.h"
69 #include "wine/debug.h"
70 #include "thread.h"
71 #include "wine/server.h"
72 #include "ntdll_misc.h"
74 #include "winternl.h"
75 #include "winioctl.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
79 mode_t FILE_umask = 0;
81 #define SECSPERDAY 86400
82 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
84 /**************************************************************************
85 * NtOpenFile [NTDLL.@]
86 * ZwOpenFile [NTDLL.@]
88 * Open a file.
90 * PARAMS
91 * handle [O] Variable that receives the file handle on return
92 * access [I] Access desired by the caller to the file
93 * attr [I] Structure describing the file to be opened
94 * io [O] Receives details about the result of the operation
95 * sharing [I] Type of shared access the caller requires
96 * options [I] Options for the file open
98 * RETURNS
99 * Success: 0. FileHandle and IoStatusBlock are updated.
100 * Failure: An NTSTATUS error code describing the error.
102 NTSTATUS WINAPI NtOpenFile( PHANDLE handle, ACCESS_MASK access,
103 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK io,
104 ULONG sharing, ULONG options )
106 return NtCreateFile( handle, access, attr, io, NULL, 0,
107 sharing, FILE_OPEN, options, NULL, 0 );
110 /**************************************************************************
111 * NtCreateFile [NTDLL.@]
112 * ZwCreateFile [NTDLL.@]
114 * Either create a new file or directory, or open an existing file, device,
115 * directory or volume.
117 * PARAMS
118 * handle [O] Points to a variable which receives the file handle on return
119 * access [I] Desired access to the file
120 * attr [I] Structure describing the file
121 * io [O] Receives information about the operation on return
122 * alloc_size [I] Initial size of the file in bytes
123 * attributes [I] Attributes to create the file with
124 * sharing [I] Type of shared access the caller would like to the file
125 * disposition [I] Specifies what to do, depending on whether the file already exists
126 * options [I] Options for creating a new file
127 * ea_buffer [I] Pointer to an extended attributes buffer
128 * ea_length [I] Length of ea_buffer
130 * RETURNS
131 * Success: 0. handle and io are updated.
132 * Failure: An NTSTATUS error code describing the error.
134 NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
135 PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
136 ULONG attributes, ULONG sharing, ULONG disposition,
137 ULONG options, PVOID ea_buffer, ULONG ea_length )
139 static const WCHAR pipeW[] = {'\\','?','?','\\','p','i','p','e','\\'};
140 static const WCHAR mailslotW[] = {'\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
141 ANSI_STRING unix_name;
142 int created = FALSE;
144 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
145 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
146 handle, access, debugstr_us(attr->ObjectName), attr->Attributes,
147 attr->RootDirectory, attr->SecurityDescriptor, io, alloc_size,
148 attributes, sharing, disposition, options, ea_buffer, ea_length );
150 if (!attr || !attr->ObjectName) return STATUS_INVALID_PARAMETER;
152 if (attr->RootDirectory)
154 FIXME( "RootDirectory %p not supported\n", attr->RootDirectory );
155 return STATUS_OBJECT_NAME_NOT_FOUND;
157 if (alloc_size) FIXME( "alloc_size not supported\n" );
159 /* check for named pipe */
161 if (attr->ObjectName->Length > sizeof(pipeW) &&
162 !memicmpW( attr->ObjectName->Buffer, pipeW, sizeof(pipeW)/sizeof(WCHAR) ))
164 SERVER_START_REQ( open_named_pipe )
166 req->access = access;
167 req->flags = options;
168 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
169 wine_server_add_data( req, attr->ObjectName->Buffer + 4,
170 attr->ObjectName->Length - 4*sizeof(WCHAR) );
171 io->u.Status = wine_server_call( req );
172 *handle = reply->handle;
174 SERVER_END_REQ;
175 return io->u.Status;
178 /* check for mailslot */
180 if (attr->ObjectName->Length > sizeof(mailslotW) &&
181 !memicmpW( attr->ObjectName->Buffer, mailslotW, sizeof(mailslotW)/sizeof(WCHAR) ))
183 SERVER_START_REQ( open_mailslot )
185 req->access = access & GENERIC_WRITE;
186 req->sharing = sharing;
187 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
188 wine_server_add_data( req, attr->ObjectName->Buffer + 4,
189 attr->ObjectName->Length - 4*sizeof(WCHAR) );
190 io->u.Status = wine_server_call( req );
191 *handle = reply->handle;
193 SERVER_END_REQ;
194 return io->u.Status;
197 io->u.Status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, disposition,
198 !(attr->Attributes & OBJ_CASE_INSENSITIVE) );
200 if (io->u.Status == STATUS_NO_SUCH_FILE &&
201 disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
203 created = TRUE;
204 io->u.Status = STATUS_SUCCESS;
207 if (io->u.Status == STATUS_SUCCESS)
209 SERVER_START_REQ( create_file )
211 req->access = access;
212 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
213 req->sharing = sharing;
214 req->create = disposition;
215 req->options = options;
216 req->attrs = attributes;
217 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
218 io->u.Status = wine_server_call( req );
219 *handle = reply->handle;
221 SERVER_END_REQ;
222 RtlFreeAnsiString( &unix_name );
224 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), io->u.Status );
226 if (io->u.Status == STATUS_SUCCESS)
228 if (created) io->Information = FILE_CREATED;
229 else switch(disposition)
231 case FILE_SUPERSEDE:
232 io->Information = FILE_SUPERSEDED;
233 break;
234 case FILE_CREATE:
235 io->Information = FILE_CREATED;
236 break;
237 case FILE_OPEN:
238 case FILE_OPEN_IF:
239 io->Information = FILE_OPENED;
240 break;
241 case FILE_OVERWRITE:
242 case FILE_OVERWRITE_IF:
243 io->Information = FILE_OVERWRITTEN;
244 break;
248 return io->u.Status;
251 /***********************************************************************
252 * Asynchronous file I/O *
254 static void WINAPI FILE_AsyncReadService(void*, PIO_STATUS_BLOCK, ULONG);
255 static void WINAPI FILE_AsyncWriteService(void*, PIO_STATUS_BLOCK, ULONG);
257 typedef struct async_fileio
259 HANDLE handle;
260 PIO_APC_ROUTINE apc;
261 void* apc_user;
262 char* buffer;
263 unsigned int count;
264 off_t offset;
265 int queue_apc_on_error;
266 BOOL avail_mode;
267 int fd;
268 HANDLE event;
269 } async_fileio;
271 static void fileio_terminate(async_fileio *fileio, IO_STATUS_BLOCK* iosb)
273 TRACE("data: %p\n", fileio);
275 wine_server_release_fd( fileio->handle, fileio->fd );
276 if ( fileio->event != INVALID_HANDLE_VALUE )
277 NtSetEvent( fileio->event, NULL );
279 if (fileio->apc &&
280 (iosb->u.Status == STATUS_SUCCESS || fileio->queue_apc_on_error))
281 fileio->apc( fileio->apc_user, iosb, iosb->Information );
283 RtlFreeHeap( GetProcessHeap(), 0, fileio );
287 static ULONG fileio_queue_async(async_fileio* fileio, IO_STATUS_BLOCK* iosb,
288 BOOL do_read)
290 PIO_APC_ROUTINE apc = do_read ? FILE_AsyncReadService : FILE_AsyncWriteService;
291 NTSTATUS status;
293 SERVER_START_REQ( register_async )
295 req->handle = fileio->handle;
296 req->io_apc = apc;
297 req->io_sb = iosb;
298 req->io_user = fileio;
299 req->type = do_read ? ASYNC_TYPE_READ : ASYNC_TYPE_WRITE;
300 req->count = (fileio->count < iosb->Information) ?
301 0 : fileio->count - iosb->Information;
302 status = wine_server_call( req );
304 SERVER_END_REQ;
306 if ( status ) iosb->u.Status = status;
307 if ( iosb->u.Status != STATUS_PENDING )
309 (apc)( fileio, iosb, iosb->u.Status );
310 return iosb->u.Status;
312 NtCurrentTeb()->num_async_io++;
313 return STATUS_SUCCESS;
316 /***********************************************************************
317 * FILE_GetNtStatus(void)
319 * Retrieve the Nt Status code from errno.
320 * Try to be consistent with FILE_SetDosError().
322 NTSTATUS FILE_GetNtStatus(void)
324 int err = errno;
326 TRACE( "errno = %d\n", errno );
327 switch (err)
329 case EAGAIN: return STATUS_SHARING_VIOLATION;
330 case EBADF: return STATUS_INVALID_HANDLE;
331 case ENOSPC: return STATUS_DISK_FULL;
332 case EPERM:
333 case EROFS:
334 case EACCES: return STATUS_ACCESS_DENIED;
335 case ENOTDIR: return STATUS_OBJECT_PATH_NOT_FOUND;
336 case ENOENT: return STATUS_OBJECT_NAME_NOT_FOUND;
337 case EISDIR: return STATUS_FILE_IS_A_DIRECTORY;
338 case EMFILE:
339 case ENFILE: return STATUS_TOO_MANY_OPENED_FILES;
340 case EINVAL: return STATUS_INVALID_PARAMETER;
341 case ENOTEMPTY: return STATUS_DIRECTORY_NOT_EMPTY;
342 case EPIPE: return STATUS_PIPE_BROKEN;
343 case EIO: return STATUS_DEVICE_NOT_READY;
344 #ifdef ENOMEDIUM
345 case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
346 #endif
347 case ENOTTY:
348 case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
349 case ECONNRESET:return STATUS_PIPE_DISCONNECTED;
350 case ENOEXEC: /* ?? */
351 case ESPIPE: /* ?? */
352 case EEXIST: /* ?? */
353 default:
354 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err );
355 return STATUS_UNSUCCESSFUL;
359 /***********************************************************************
360 * FILE_AsyncReadService (INTERNAL)
362 * This function is called while the client is waiting on the
363 * server, so we can't make any server calls here.
365 static void WINAPI FILE_AsyncReadService(void *user, PIO_STATUS_BLOCK iosb, ULONG status)
367 async_fileio *fileio = (async_fileio*)user;
368 int result;
369 int already = iosb->Information;
371 TRACE("%p %p 0x%lx\n", iosb, fileio->buffer, status);
373 switch (status)
375 case STATUS_ALERTED: /* got some new data */
376 if (iosb->u.Status != STATUS_PENDING) FIXME("unexpected status %08lx\n", iosb->u.Status);
377 /* check to see if the data is ready (non-blocking) */
378 if ( fileio->avail_mode )
379 result = read(fileio->fd, &fileio->buffer[already],
380 fileio->count - already);
381 else
383 result = pread(fileio->fd, &fileio->buffer[already],
384 fileio->count - already,
385 fileio->offset + already);
386 if ((result < 0) && (errno == ESPIPE))
387 result = read(fileio->fd, &fileio->buffer[already],
388 fileio->count - already);
391 if (result < 0)
393 if (errno == EAGAIN || errno == EINTR)
395 TRACE("Deferred read %d\n", errno);
396 iosb->u.Status = STATUS_PENDING;
398 else /* check to see if the transfer is complete */
399 iosb->u.Status = FILE_GetNtStatus();
401 else if (result == 0)
403 iosb->u.Status = iosb->Information ? STATUS_SUCCESS : STATUS_END_OF_FILE;
405 else
407 iosb->Information += result;
408 if (iosb->Information >= fileio->count || fileio->avail_mode)
409 iosb->u.Status = STATUS_SUCCESS;
410 else
412 /* if we only have to read the available data, and none is available,
413 * simply cancel the request. If data was available, it has been read
414 * while in by previous call (NtDelayExecution)
416 iosb->u.Status = (fileio->avail_mode) ? STATUS_SUCCESS : STATUS_PENDING;
419 TRACE("read %d more bytes %ld/%d so far (%s)\n",
420 result, iosb->Information, fileio->count,
421 (iosb->u.Status == STATUS_SUCCESS) ? "success" : "pending");
423 /* queue another async operation ? */
424 if (iosb->u.Status == STATUS_PENDING)
425 fileio_queue_async(fileio, iosb, TRUE);
426 else
427 fileio_terminate(fileio, iosb);
428 break;
429 default:
430 iosb->u.Status = status;
431 fileio_terminate(fileio, iosb);
432 break;
437 /******************************************************************************
438 * NtReadFile [NTDLL.@]
439 * ZwReadFile [NTDLL.@]
441 * Read from an open file handle.
443 * PARAMS
444 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
445 * Event [I] Event to signal upon completion (or NULL)
446 * ApcRoutine [I] Callback to call upon completion (or NULL)
447 * ApcContext [I] Context for ApcRoutine (or NULL)
448 * IoStatusBlock [O] Receives information about the operation on return
449 * Buffer [O] Destination for the data read
450 * Length [I] Size of Buffer
451 * ByteOffset [O] Destination for the new file pointer position (or NULL)
452 * Key [O] Function unknown (may be NULL)
454 * RETURNS
455 * Success: 0. IoStatusBlock is updated, and the Information member contains
456 * The number of bytes read.
457 * Failure: An NTSTATUS error code describing the error.
459 NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
460 PIO_APC_ROUTINE apc, void* apc_user,
461 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
462 PLARGE_INTEGER offset, PULONG key)
464 int unix_handle, flags;
466 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
467 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
469 if (!io_status) return STATUS_ACCESS_VIOLATION;
471 io_status->Information = 0;
472 io_status->u.Status = wine_server_handle_to_fd( hFile, GENERIC_READ, &unix_handle, &flags );
473 if (io_status->u.Status) return io_status->u.Status;
475 if (flags & FD_FLAG_RECV_SHUTDOWN)
477 wine_server_release_fd( hFile, unix_handle );
478 return STATUS_PIPE_DISCONNECTED;
481 if (flags & FD_FLAG_TIMEOUT)
483 if (hEvent)
485 /* this shouldn't happen, but check it */
486 FIXME("NIY-hEvent\n");
487 wine_server_release_fd( hFile, unix_handle );
488 return STATUS_NOT_IMPLEMENTED;
490 io_status->u.Status = NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, NULL, 0, 0);
491 if (io_status->u.Status)
493 wine_server_release_fd( hFile, unix_handle );
494 return io_status->u.Status;
498 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
500 async_fileio* fileio;
501 NTSTATUS ret;
503 if (!(fileio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
505 wine_server_release_fd( hFile, unix_handle );
506 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
507 return STATUS_NO_MEMORY;
509 fileio->handle = hFile;
510 fileio->count = length;
511 if ( offset == NULL )
512 fileio->offset = 0;
513 else
515 fileio->offset = offset->QuadPart;
516 if (offset->u.HighPart && fileio->offset == offset->u.LowPart)
517 FIXME("High part of offset is lost\n");
519 fileio->apc = apc;
520 fileio->apc_user = apc_user;
521 fileio->buffer = buffer;
522 fileio->queue_apc_on_error = 0;
523 fileio->avail_mode = (flags & FD_FLAG_AVAILABLE);
524 fileio->fd = unix_handle; /* FIXME */
525 fileio->event = hEvent;
526 NtResetEvent(hEvent, NULL);
528 io_status->u.Status = STATUS_PENDING;
529 ret = fileio_queue_async(fileio, io_status, TRUE);
530 if (ret != STATUS_SUCCESS)
532 wine_server_release_fd( hFile, unix_handle );
533 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
534 return ret;
536 if (flags & FD_FLAG_TIMEOUT)
540 ret = NtWaitForSingleObject(hEvent, TRUE, NULL);
542 while (ret == STATUS_USER_APC && io_status->u.Status == STATUS_PENDING);
543 NtClose(hEvent);
544 if (ret != STATUS_USER_APC)
545 fileio->queue_apc_on_error = 1;
547 else
549 LARGE_INTEGER timeout;
551 /* let some APC be run, this will read some already pending data */
552 timeout.u.LowPart = timeout.u.HighPart = 0;
553 ret = NtDelayExecution( TRUE, &timeout );
554 /* the apc didn't run and therefore the completion routine now
555 * needs to be sent errors.
556 * Note that there is no race between setting this flag and
557 * returning errors because apc's are run only during alertable
558 * waits */
559 if (ret != STATUS_USER_APC)
560 fileio->queue_apc_on_error = 1;
562 TRACE("= 0x%08lx\n", io_status->u.Status);
563 return io_status->u.Status;
566 if (offset)
568 FILE_POSITION_INFORMATION fpi;
570 fpi.CurrentByteOffset = *offset;
571 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
572 FilePositionInformation);
573 if (io_status->u.Status)
575 wine_server_release_fd( hFile, unix_handle );
576 return io_status->u.Status;
579 /* code for synchronous reads */
580 while ((io_status->Information = read( unix_handle, buffer, length )) == -1)
582 if ((errno == EAGAIN) || (errno == EINTR)) continue;
583 if (errno == EFAULT)
585 io_status->Information = 0;
586 io_status->u.Status = STATUS_ACCESS_VIOLATION;
588 else io_status->u.Status = FILE_GetNtStatus();
589 break;
591 wine_server_release_fd( hFile, unix_handle );
592 TRACE("= 0x%08lx\n", io_status->u.Status);
593 return io_status->u.Status;
596 /***********************************************************************
597 * FILE_AsyncWriteService (INTERNAL)
599 * This function is called while the client is waiting on the
600 * server, so we can't make any server calls here.
602 static void WINAPI FILE_AsyncWriteService(void *ovp, IO_STATUS_BLOCK *iosb, ULONG status)
604 async_fileio *fileio = (async_fileio *) ovp;
605 int result;
606 int already = iosb->Information;
608 TRACE("(%p %p 0x%lx)\n",iosb, fileio->buffer, status);
610 switch (status)
612 case STATUS_ALERTED:
613 /* write some data (non-blocking) */
614 if ( fileio->avail_mode )
615 result = write(fileio->fd, &fileio->buffer[already],
616 fileio->count - already);
617 else
619 result = pwrite(fileio->fd, &fileio->buffer[already],
620 fileio->count - already, fileio->offset + already);
621 if ((result < 0) && (errno == ESPIPE))
622 result = write(fileio->fd, &fileio->buffer[already],
623 fileio->count - already);
626 if (result < 0)
628 if (errno == EAGAIN || errno == EINTR) iosb->u.Status = STATUS_PENDING;
629 else iosb->u.Status = FILE_GetNtStatus();
631 else
633 iosb->Information += result;
634 iosb->u.Status = (iosb->Information < fileio->count) ? STATUS_PENDING : STATUS_SUCCESS;
635 TRACE("wrote %d more bytes %ld/%d so far\n",
636 result, iosb->Information, fileio->count);
638 if (iosb->u.Status == STATUS_PENDING)
639 fileio_queue_async(fileio, iosb, FALSE);
640 else
641 fileio_terminate(fileio, iosb);
642 break;
643 default:
644 iosb->u.Status = status;
645 fileio_terminate(fileio, iosb);
646 break;
650 /******************************************************************************
651 * NtWriteFile [NTDLL.@]
652 * ZwWriteFile [NTDLL.@]
654 * Write to an open file handle.
656 * PARAMS
657 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
658 * Event [I] Event to signal upon completion (or NULL)
659 * ApcRoutine [I] Callback to call upon completion (or NULL)
660 * ApcContext [I] Context for ApcRoutine (or NULL)
661 * IoStatusBlock [O] Receives information about the operation on return
662 * Buffer [I] Source for the data to write
663 * Length [I] Size of Buffer
664 * ByteOffset [O] Destination for the new file pointer position (or NULL)
665 * Key [O] Function unknown (may be NULL)
667 * RETURNS
668 * Success: 0. IoStatusBlock is updated, and the Information member contains
669 * The number of bytes written.
670 * Failure: An NTSTATUS error code describing the error.
672 NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
673 PIO_APC_ROUTINE apc, void* apc_user,
674 PIO_STATUS_BLOCK io_status,
675 const void* buffer, ULONG length,
676 PLARGE_INTEGER offset, PULONG key)
678 int unix_handle, flags;
680 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
681 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
683 if (!io_status) return STATUS_ACCESS_VIOLATION;
685 io_status->Information = 0;
686 io_status->u.Status = wine_server_handle_to_fd( hFile, GENERIC_WRITE, &unix_handle, &flags );
687 if (io_status->u.Status) return io_status->u.Status;
689 if (flags & FD_FLAG_SEND_SHUTDOWN)
691 wine_server_release_fd( hFile, unix_handle );
692 return STATUS_PIPE_DISCONNECTED;
695 if (flags & FD_FLAG_TIMEOUT)
697 if (hEvent)
699 /* this shouldn't happen, but check it */
700 FIXME("NIY-hEvent\n");
701 wine_server_release_fd( hFile, unix_handle );
702 return STATUS_NOT_IMPLEMENTED;
704 io_status->u.Status = NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, NULL, 0, 0);
705 if (io_status->u.Status)
707 wine_server_release_fd( hFile, unix_handle );
708 return io_status->u.Status;
712 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
714 async_fileio* fileio;
715 NTSTATUS ret;
717 if (!(fileio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
719 wine_server_release_fd( hFile, unix_handle );
720 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
721 return STATUS_NO_MEMORY;
723 fileio->handle = hFile;
724 fileio->count = length;
725 if (offset)
727 fileio->offset = offset->QuadPart;
728 if (offset->u.HighPart && fileio->offset == offset->u.LowPart)
729 FIXME("High part of offset is lost\n");
731 else
733 fileio->offset = 0;
735 fileio->apc = apc;
736 fileio->apc_user = apc_user;
737 fileio->buffer = (void*)buffer;
738 fileio->queue_apc_on_error = 0;
739 fileio->avail_mode = (flags & FD_FLAG_AVAILABLE);
740 fileio->fd = unix_handle; /* FIXME */
741 fileio->event = hEvent;
742 NtResetEvent(hEvent, NULL);
744 io_status->Information = 0;
745 io_status->u.Status = STATUS_PENDING;
746 ret = fileio_queue_async(fileio, io_status, FALSE);
747 if (ret != STATUS_SUCCESS)
749 wine_server_release_fd( hFile, unix_handle );
750 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
751 return ret;
753 if (flags & FD_FLAG_TIMEOUT)
757 ret = NtWaitForSingleObject(hEvent, TRUE, NULL);
759 while (ret == STATUS_USER_APC && io_status->u.Status == STATUS_PENDING);
760 NtClose(hEvent);
761 if (ret != STATUS_USER_APC)
762 fileio->queue_apc_on_error = 1;
764 else
766 LARGE_INTEGER timeout;
768 /* let some APC be run, this will write as much data as possible */
769 timeout.u.LowPart = timeout.u.HighPart = 0;
770 ret = NtDelayExecution( TRUE, &timeout );
771 /* the apc didn't run and therefore the completion routine now
772 * needs to be sent errors.
773 * Note that there is no race between setting this flag and
774 * returning errors because apc's are run only during alertable
775 * waits */
776 if (ret != STATUS_USER_APC)
777 fileio->queue_apc_on_error = 1;
779 return io_status->u.Status;
782 if (offset)
784 FILE_POSITION_INFORMATION fpi;
786 fpi.CurrentByteOffset = *offset;
787 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
788 FilePositionInformation);
789 if (io_status->u.Status)
791 wine_server_release_fd( hFile, unix_handle );
792 return io_status->u.Status;
796 /* synchronous file write */
797 while ((io_status->Information = write( unix_handle, buffer, length )) == -1)
799 if ((errno == EAGAIN) || (errno == EINTR)) continue;
800 if (errno == EFAULT)
802 io_status->Information = 0;
803 io_status->u.Status = STATUS_INVALID_USER_BUFFER;
805 else if (errno == ENOSPC) io_status->u.Status = STATUS_DISK_FULL;
806 else io_status->u.Status = FILE_GetNtStatus();
807 break;
809 wine_server_release_fd( hFile, unix_handle );
810 return io_status->u.Status;
813 /**************************************************************************
814 * NtDeviceIoControlFile [NTDLL.@]
815 * ZwDeviceIoControlFile [NTDLL.@]
817 * Perform an I/O control operation on an open file handle.
819 * PARAMS
820 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
821 * Event [I] Event to signal upon completion (or NULL)
822 * ApcRoutine [I] Callback to call upon completion (or NULL)
823 * ApcContext [I] Context for ApcRoutine (or NULL)
824 * IoStatusBlock [O] Receives information about the operation on return
825 * IoControlCode [I] Control code for the operation to perform
826 * InputBuffer [I] Source for any input data required (or NULL)
827 * InputBufferSize [I] Size of InputBuffer
828 * OutputBuffer [O] Source for any output data returned (or NULL)
829 * OutputBufferSize [I] Size of OutputBuffer
831 * RETURNS
832 * Success: 0. IoStatusBlock is updated.
833 * Failure: An NTSTATUS error code describing the error.
835 NTSTATUS WINAPI NtDeviceIoControlFile(HANDLE DeviceHandle, HANDLE hEvent,
836 PIO_APC_ROUTINE UserApcRoutine,
837 PVOID UserApcContext,
838 PIO_STATUS_BLOCK IoStatusBlock,
839 ULONG IoControlCode,
840 PVOID InputBuffer,
841 ULONG InputBufferSize,
842 PVOID OutputBuffer,
843 ULONG OutputBufferSize)
845 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
846 DeviceHandle, hEvent, UserApcRoutine, UserApcContext,
847 IoStatusBlock, IoControlCode,
848 InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize);
850 if (CDROM_DeviceIoControl(DeviceHandle, hEvent,
851 UserApcRoutine, UserApcContext,
852 IoStatusBlock, IoControlCode,
853 InputBuffer, InputBufferSize,
854 OutputBuffer, OutputBufferSize) == STATUS_NO_SUCH_DEVICE)
856 /* it wasn't a CDROM */
857 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode);
858 IoStatusBlock->u.Status = STATUS_NOT_IMPLEMENTED;
859 IoStatusBlock->Information = 0;
860 if (hEvent) NtSetEvent(hEvent, NULL);
862 return IoStatusBlock->u.Status;
865 /******************************************************************************
866 * NtFsControlFile [NTDLL.@]
867 * ZwFsControlFile [NTDLL.@]
869 NTSTATUS WINAPI NtFsControlFile(
870 IN HANDLE DeviceHandle,
871 IN HANDLE Event OPTIONAL,
872 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
873 IN PVOID ApcContext OPTIONAL,
874 OUT PIO_STATUS_BLOCK IoStatusBlock,
875 IN ULONG IoControlCode,
876 IN PVOID InputBuffer,
877 IN ULONG InputBufferSize,
878 OUT PVOID OutputBuffer,
879 IN ULONG OutputBufferSize)
881 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
882 DeviceHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,IoControlCode,
883 InputBuffer,InputBufferSize,OutputBuffer,OutputBufferSize);
884 return 0;
887 /******************************************************************************
888 * NtSetVolumeInformationFile [NTDLL.@]
889 * ZwSetVolumeInformationFile [NTDLL.@]
891 * Set volume information for an open file handle.
893 * PARAMS
894 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
895 * IoStatusBlock [O] Receives information about the operation on return
896 * FsInformation [I] Source for volume information
897 * Length [I] Size of FsInformation
898 * FsInformationClass [I] Type of volume information to set
900 * RETURNS
901 * Success: 0. IoStatusBlock is updated.
902 * Failure: An NTSTATUS error code describing the error.
904 NTSTATUS WINAPI NtSetVolumeInformationFile(
905 IN HANDLE FileHandle,
906 PIO_STATUS_BLOCK IoStatusBlock,
907 PVOID FsInformation,
908 ULONG Length,
909 FS_INFORMATION_CLASS FsInformationClass)
911 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
912 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
913 return 0;
916 /******************************************************************************
917 * NtQueryInformationFile [NTDLL.@]
918 * ZwQueryInformationFile [NTDLL.@]
920 * Get information about an open file handle.
922 * PARAMS
923 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
924 * io [O] Receives information about the operation on return
925 * ptr [O] Destination for file information
926 * len [I] Size of FileInformation
927 * class [I] Type of file information to get
929 * RETURNS
930 * Success: 0. IoStatusBlock and FileInformation are updated.
931 * Failure: An NTSTATUS error code describing the error.
933 NTSTATUS WINAPI NtQueryInformationFile( HANDLE hFile, PIO_STATUS_BLOCK io,
934 PVOID ptr, LONG len, FILE_INFORMATION_CLASS class )
936 static const size_t info_sizes[] =
939 sizeof(FILE_DIRECTORY_INFORMATION), /* FileDirectoryInformation */
940 sizeof(FILE_FULL_DIRECTORY_INFORMATION), /* FileFullDirectoryInformation */
941 sizeof(FILE_BOTH_DIRECTORY_INFORMATION), /* FileBothDirectoryInformation */
942 sizeof(FILE_BASIC_INFORMATION), /* FileBasicInformation */
943 sizeof(FILE_STANDARD_INFORMATION), /* FileStandardInformation */
944 sizeof(FILE_INTERNAL_INFORMATION), /* FileInternalInformation */
945 sizeof(FILE_EA_INFORMATION), /* FileEaInformation */
946 sizeof(FILE_ACCESS_INFORMATION), /* FileAccessInformation */
947 sizeof(FILE_NAME_INFORMATION)-sizeof(WCHAR), /* FileNameInformation */
948 sizeof(FILE_RENAME_INFORMATION)-sizeof(WCHAR), /* FileRenameInformation */
949 0, /* FileLinkInformation */
950 sizeof(FILE_NAMES_INFORMATION)-sizeof(WCHAR), /* FileNamesInformation */
951 sizeof(FILE_DISPOSITION_INFORMATION), /* FileDispositionInformation */
952 sizeof(FILE_POSITION_INFORMATION), /* FilePositionInformation */
953 sizeof(FILE_FULL_EA_INFORMATION), /* FileFullEaInformation */
954 sizeof(FILE_MODE_INFORMATION), /* FileModeInformation */
955 sizeof(FILE_ALIGNMENT_INFORMATION), /* FileAlignmentInformation */
956 sizeof(FILE_ALL_INFORMATION)-sizeof(WCHAR), /* FileAllInformation */
957 sizeof(FILE_ALLOCATION_INFORMATION), /* FileAllocationInformation */
958 sizeof(FILE_END_OF_FILE_INFORMATION), /* FileEndOfFileInformation */
959 0, /* FileAlternateNameInformation */
960 sizeof(FILE_STREAM_INFORMATION)-sizeof(WCHAR), /* FileStreamInformation */
961 0, /* FilePipeInformation */
962 0, /* FilePipeLocalInformation */
963 0, /* FilePipeRemoteInformation */
964 sizeof(FILE_MAILSLOT_QUERY_INFORMATION), /* FileMailslotQueryInformation */
965 0, /* FileMailslotSetInformation */
966 0, /* FileCompressionInformation */
967 0, /* FileObjectIdInformation */
968 0, /* FileCompletionInformation */
969 0, /* FileMoveClusterInformation */
970 0, /* FileQuotaInformation */
971 0, /* FileReparsePointInformation */
972 0, /* FileNetworkOpenInformation */
973 0, /* FileAttributeTagInformation */
974 0 /* FileTrackingInformation */
977 struct stat st;
978 int fd;
980 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile, io, ptr, len, class);
982 io->Information = 0;
984 if (class <= 0 || class >= FileMaximumInformation)
985 return io->u.Status = STATUS_INVALID_INFO_CLASS;
986 if (!info_sizes[class])
988 FIXME("Unsupported class (%d)\n", class);
989 return io->u.Status = STATUS_NOT_IMPLEMENTED;
991 if (len < info_sizes[class])
992 return io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
994 if ((io->u.Status = wine_server_handle_to_fd( hFile, 0, &fd, NULL )))
995 return io->u.Status;
997 switch (class)
999 case FileBasicInformation:
1001 FILE_BASIC_INFORMATION *info = ptr;
1003 if (fstat( fd, &st ) == -1)
1004 io->u.Status = FILE_GetNtStatus();
1005 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1006 io->u.Status = STATUS_INVALID_INFO_CLASS;
1007 else
1009 if (S_ISDIR(st.st_mode)) info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1010 else info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1011 if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1012 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1013 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime);
1014 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime);
1015 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime);
1016 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime);
1019 break;
1020 case FileStandardInformation:
1022 FILE_STANDARD_INFORMATION *info = ptr;
1024 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1025 else
1027 if ((info->Directory = S_ISDIR(st.st_mode)))
1029 info->AllocationSize.QuadPart = 0;
1030 info->EndOfFile.QuadPart = 0;
1031 info->NumberOfLinks = 1;
1032 info->DeletePending = FALSE;
1034 else
1036 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1037 info->EndOfFile.QuadPart = st.st_size;
1038 info->NumberOfLinks = st.st_nlink;
1039 info->DeletePending = FALSE; /* FIXME */
1043 break;
1044 case FilePositionInformation:
1046 FILE_POSITION_INFORMATION *info = ptr;
1047 off_t res = lseek( fd, 0, SEEK_CUR );
1048 if (res == (off_t)-1) io->u.Status = FILE_GetNtStatus();
1049 else info->CurrentByteOffset.QuadPart = res;
1051 break;
1052 case FileInternalInformation:
1054 FILE_INTERNAL_INFORMATION *info = ptr;
1056 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1057 else info->IndexNumber.QuadPart = st.st_ino;
1059 break;
1060 case FileEaInformation:
1062 FILE_EA_INFORMATION *info = ptr;
1063 info->EaSize = 0;
1065 break;
1066 case FileEndOfFileInformation:
1068 FILE_END_OF_FILE_INFORMATION *info = ptr;
1070 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1071 else info->EndOfFile.QuadPart = S_ISDIR(st.st_mode) ? 0 : st.st_size;
1073 break;
1074 case FileAllInformation:
1076 FILE_ALL_INFORMATION *info = ptr;
1078 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1079 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1080 io->u.Status = STATUS_INVALID_INFO_CLASS;
1081 else
1083 if ((info->StandardInformation.Directory = S_ISDIR(st.st_mode)))
1085 info->BasicInformation.FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1086 info->StandardInformation.AllocationSize.QuadPart = 0;
1087 info->StandardInformation.EndOfFile.QuadPart = 0;
1088 info->StandardInformation.NumberOfLinks = 1;
1089 info->StandardInformation.DeletePending = FALSE;
1091 else
1093 info->BasicInformation.FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1094 info->StandardInformation.AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1095 info->StandardInformation.EndOfFile.QuadPart = st.st_size;
1096 info->StandardInformation.NumberOfLinks = st.st_nlink;
1097 info->StandardInformation.DeletePending = FALSE; /* FIXME */
1099 if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1100 info->BasicInformation.FileAttributes |= FILE_ATTRIBUTE_READONLY;
1101 RtlSecondsSince1970ToTime( st.st_mtime, &info->BasicInformation.CreationTime);
1102 RtlSecondsSince1970ToTime( st.st_mtime, &info->BasicInformation.LastWriteTime);
1103 RtlSecondsSince1970ToTime( st.st_ctime, &info->BasicInformation.ChangeTime);
1104 RtlSecondsSince1970ToTime( st.st_atime, &info->BasicInformation.LastAccessTime);
1105 info->InternalInformation.IndexNumber.QuadPart = st.st_ino;
1106 info->EaInformation.EaSize = 0;
1107 info->AccessInformation.AccessFlags = 0; /* FIXME */
1108 info->PositionInformation.CurrentByteOffset.QuadPart = lseek( fd, 0, SEEK_CUR );
1109 info->ModeInformation.Mode = 0; /* FIXME */
1110 info->AlignmentInformation.AlignmentRequirement = 1; /* FIXME */
1111 info->NameInformation.FileNameLength = 0;
1112 io->Information = sizeof(*info) - sizeof(WCHAR);
1115 break;
1116 case FileMailslotQueryInformation:
1118 FILE_MAILSLOT_QUERY_INFORMATION *info = ptr;
1120 SERVER_START_REQ( set_mailslot_info )
1122 req->handle = hFile;
1123 req->flags = 0;
1124 io->u.Status = wine_server_call( req );
1125 if( io->u.Status == STATUS_SUCCESS )
1127 info->MaximumMessageSize = reply->max_msgsize;
1128 info->MailslotQuota = 0;
1129 info->NextMessageSize = reply->next_msgsize;
1130 info->MessagesAvailable = reply->msg_count;
1131 info->ReadTimeout.QuadPart = reply->read_timeout * -10000;
1134 SERVER_END_REQ;
1136 break;
1137 default:
1138 FIXME("Unsupported class (%d)\n", class);
1139 io->u.Status = STATUS_NOT_IMPLEMENTED;
1140 break;
1142 wine_server_release_fd( hFile, fd );
1143 if (io->u.Status == STATUS_SUCCESS && !io->Information) io->Information = info_sizes[class];
1144 return io->u.Status;
1147 /******************************************************************************
1148 * NtSetInformationFile [NTDLL.@]
1149 * ZwSetInformationFile [NTDLL.@]
1151 * Set information about an open file handle.
1153 * PARAMS
1154 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1155 * io [O] Receives information about the operation on return
1156 * ptr [I] Source for file information
1157 * len [I] Size of FileInformation
1158 * class [I] Type of file information to set
1160 * RETURNS
1161 * Success: 0. io is updated.
1162 * Failure: An NTSTATUS error code describing the error.
1164 NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
1165 PVOID ptr, ULONG len, FILE_INFORMATION_CLASS class)
1167 int fd;
1169 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle, io, ptr, len, class);
1171 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL )))
1172 return io->u.Status;
1174 io->u.Status = STATUS_SUCCESS;
1175 switch (class)
1177 case FileBasicInformation:
1178 if (len >= sizeof(FILE_BASIC_INFORMATION))
1180 struct stat st;
1181 const FILE_BASIC_INFORMATION *info = ptr;
1183 if (info->LastAccessTime.QuadPart || info->LastWriteTime.QuadPart)
1185 ULONGLONG sec, nsec;
1186 struct timeval tv[2];
1188 if (!info->LastAccessTime.QuadPart || !info->LastWriteTime.QuadPart)
1191 tv[0].tv_sec = tv[0].tv_usec = 0;
1192 tv[1].tv_sec = tv[1].tv_usec = 0;
1193 if (!fstat( fd, &st ))
1195 tv[0].tv_sec = st.st_atime;
1196 tv[1].tv_sec = st.st_mtime;
1199 if (info->LastAccessTime.QuadPart)
1201 sec = RtlLargeIntegerDivide( info->LastAccessTime.QuadPart, 10000000, &nsec );
1202 tv[0].tv_sec = sec - SECS_1601_TO_1970;
1203 tv[0].tv_usec = (UINT)nsec / 10;
1205 if (info->LastWriteTime.QuadPart)
1207 sec = RtlLargeIntegerDivide( info->LastWriteTime.QuadPart, 10000000, &nsec );
1208 tv[1].tv_sec = sec - SECS_1601_TO_1970;
1209 tv[1].tv_usec = (UINT)nsec / 10;
1211 if (futimes( fd, tv ) == -1) io->u.Status = FILE_GetNtStatus();
1214 if (io->u.Status == STATUS_SUCCESS && info->FileAttributes)
1216 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1217 else
1219 if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
1221 if (S_ISDIR( st.st_mode))
1222 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1223 else
1224 st.st_mode &= ~0222; /* clear write permission bits */
1226 else
1228 /* add write permission only where we already have read permission */
1229 st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~FILE_umask);
1231 if (fchmod( fd, st.st_mode ) == -1) io->u.Status = FILE_GetNtStatus();
1235 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1236 break;
1238 case FilePositionInformation:
1239 if (len >= sizeof(FILE_POSITION_INFORMATION))
1241 const FILE_POSITION_INFORMATION *info = ptr;
1243 if (lseek( fd, info->CurrentByteOffset.QuadPart, SEEK_SET ) == (off_t)-1)
1244 io->u.Status = FILE_GetNtStatus();
1246 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1247 break;
1249 case FileEndOfFileInformation:
1250 if (len >= sizeof(FILE_END_OF_FILE_INFORMATION))
1252 struct stat st;
1253 const FILE_END_OF_FILE_INFORMATION *info = ptr;
1255 /* first try normal truncate */
1256 if (ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
1258 /* now check for the need to extend the file */
1259 if (fstat( fd, &st ) != -1 && (off_t)info->EndOfFile.QuadPart > st.st_size)
1261 static const char zero;
1263 /* extend the file one byte beyond the requested size and then truncate it */
1264 /* this should work around ftruncate implementations that can't extend files */
1265 if (pwrite( fd, &zero, 1, (off_t)info->EndOfFile.QuadPart ) != -1 &&
1266 ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
1268 io->u.Status = FILE_GetNtStatus();
1270 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1271 break;
1273 case FileMailslotSetInformation:
1275 FILE_MAILSLOT_SET_INFORMATION *info = ptr;
1277 SERVER_START_REQ( set_mailslot_info )
1279 req->handle = handle;
1280 req->flags = MAILSLOT_SET_READ_TIMEOUT;
1281 req->read_timeout = info->ReadTimeout.QuadPart / -10000;
1282 io->u.Status = wine_server_call( req );
1284 SERVER_END_REQ;
1286 break;
1288 default:
1289 FIXME("Unsupported class (%d)\n", class);
1290 io->u.Status = STATUS_NOT_IMPLEMENTED;
1291 break;
1293 wine_server_release_fd( handle, fd );
1294 io->Information = 0;
1295 return io->u.Status;
1299 /******************************************************************************
1300 * NtQueryFullAttributesFile (NTDLL.@)
1302 NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
1303 FILE_NETWORK_OPEN_INFORMATION *info )
1305 ANSI_STRING unix_name;
1306 NTSTATUS status;
1308 if (!(status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, FILE_OPEN,
1309 !(attr->Attributes & OBJ_CASE_INSENSITIVE) )))
1311 struct stat st;
1313 if (stat( unix_name.Buffer, &st ) == -1)
1314 status = FILE_GetNtStatus();
1315 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1316 status = STATUS_INVALID_INFO_CLASS;
1317 else
1319 if (S_ISDIR(st.st_mode))
1321 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1322 info->AllocationSize.QuadPart = 0;
1323 info->EndOfFile.QuadPart = 0;
1325 else
1327 info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1328 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1329 info->EndOfFile.QuadPart = st.st_size;
1331 if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1332 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1333 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime );
1334 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime );
1335 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime );
1336 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime );
1337 if (DIR_is_hidden_file( attr->ObjectName ))
1338 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
1340 RtlFreeAnsiString( &unix_name );
1342 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), status );
1343 return status;
1347 /******************************************************************************
1348 * NtQueryAttributesFile (NTDLL.@)
1349 * ZwQueryAttributesFile (NTDLL.@)
1351 NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC_INFORMATION *info )
1353 FILE_NETWORK_OPEN_INFORMATION full_info;
1354 NTSTATUS status;
1356 if (!(status = NtQueryFullAttributesFile( attr, &full_info )))
1358 info->CreationTime.QuadPart = full_info.CreationTime.QuadPart;
1359 info->LastAccessTime.QuadPart = full_info.LastAccessTime.QuadPart;
1360 info->LastWriteTime.QuadPart = full_info.LastWriteTime.QuadPart;
1361 info->ChangeTime.QuadPart = full_info.ChangeTime.QuadPart;
1362 info->FileAttributes = full_info.FileAttributes;
1364 return status;
1368 /******************************************************************************
1369 * NtQueryVolumeInformationFile [NTDLL.@]
1370 * ZwQueryVolumeInformationFile [NTDLL.@]
1372 * Get volume information for an open file handle.
1374 * PARAMS
1375 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1376 * io [O] Receives information about the operation on return
1377 * buffer [O] Destination for volume information
1378 * length [I] Size of FsInformation
1379 * info_class [I] Type of volume information to set
1381 * RETURNS
1382 * Success: 0. io and buffer are updated.
1383 * Failure: An NTSTATUS error code describing the error.
1385 NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io,
1386 PVOID buffer, ULONG length,
1387 FS_INFORMATION_CLASS info_class )
1389 int fd;
1390 struct stat st;
1392 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL )) != STATUS_SUCCESS)
1393 return io->u.Status;
1395 io->u.Status = STATUS_NOT_IMPLEMENTED;
1396 io->Information = 0;
1398 switch( info_class )
1400 case FileFsVolumeInformation:
1401 FIXME( "%p: volume info not supported\n", handle );
1402 break;
1403 case FileFsLabelInformation:
1404 FIXME( "%p: label info not supported\n", handle );
1405 break;
1406 case FileFsSizeInformation:
1407 if (length < sizeof(FILE_FS_SIZE_INFORMATION))
1408 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1409 else
1411 FILE_FS_SIZE_INFORMATION *info = buffer;
1413 if (fstat( fd, &st ) < 0)
1415 io->u.Status = FILE_GetNtStatus();
1416 break;
1418 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1420 io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
1422 else
1424 /* Linux's fstatvfs is buggy */
1425 #if !defined(linux) || !defined(HAVE_FSTATFS)
1426 struct statvfs stfs;
1428 if (fstatvfs( fd, &stfs ) < 0)
1430 io->u.Status = FILE_GetNtStatus();
1431 break;
1433 info->BytesPerSector = stfs.f_frsize;
1434 #else
1435 struct statfs stfs;
1436 if (fstatfs( fd, &stfs ) < 0)
1438 io->u.Status = FILE_GetNtStatus();
1439 break;
1441 info->BytesPerSector = stfs.f_bsize;
1442 #endif
1443 info->TotalAllocationUnits.QuadPart = stfs.f_blocks;
1444 info->AvailableAllocationUnits.QuadPart = stfs.f_bavail;
1445 info->SectorsPerAllocationUnit = 1;
1446 io->Information = sizeof(*info);
1447 io->u.Status = STATUS_SUCCESS;
1450 break;
1451 case FileFsDeviceInformation:
1452 if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
1453 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1454 else
1456 FILE_FS_DEVICE_INFORMATION *info = buffer;
1458 info->Characteristics = 0;
1459 if (fstat( fd, &st ) < 0)
1461 io->u.Status = FILE_GetNtStatus();
1462 break;
1464 if (S_ISCHR( st.st_mode ))
1466 info->DeviceType = FILE_DEVICE_UNKNOWN;
1467 #ifdef linux
1468 switch(major(st.st_rdev))
1470 case MEM_MAJOR:
1471 info->DeviceType = FILE_DEVICE_NULL;
1472 break;
1473 case TTY_MAJOR:
1474 info->DeviceType = FILE_DEVICE_SERIAL_PORT;
1475 break;
1476 case LP_MAJOR:
1477 info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
1478 break;
1480 #endif
1482 else if (S_ISBLK( st.st_mode ))
1484 info->DeviceType = FILE_DEVICE_DISK;
1486 else if (S_ISFIFO( st.st_mode ) || S_ISSOCK( st.st_mode ))
1488 info->DeviceType = FILE_DEVICE_NAMED_PIPE;
1490 else /* regular file or directory */
1492 #if defined(linux) && defined(HAVE_FSTATFS)
1493 struct statfs stfs;
1495 /* check for floppy disk */
1496 if (major(st.st_dev) == FLOPPY_MAJOR)
1497 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1499 if (fstatfs( fd, &stfs ) < 0) stfs.f_type = 0;
1500 switch (stfs.f_type)
1502 case 0x9660: /* iso9660 */
1503 case 0x15013346: /* udf */
1504 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1505 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1506 break;
1507 case 0x6969: /* nfs */
1508 case 0x517B: /* smbfs */
1509 case 0x564c: /* ncpfs */
1510 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1511 info->Characteristics |= FILE_REMOTE_DEVICE;
1512 break;
1513 case 0x01021994: /* tmpfs */
1514 case 0x28cd3d45: /* cramfs */
1515 case 0x1373: /* devfs */
1516 case 0x9fa0: /* procfs */
1517 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1518 break;
1519 default:
1520 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1521 break;
1523 #elif defined(__FreeBSD__)
1524 struct statfs stfs;
1526 /* The proper way to do this in FreeBSD seems to be with the
1527 * name rather than the type, since their linux-compatible
1528 * fstatfs call converts the name to one of the Linux types.
1530 if (fstatfs( fd, &stfs ) < 0)
1531 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1532 else if (!strncmp("cd9660", stfs.f_fstypename,
1533 sizeof(stfs.f_fstypename)))
1535 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1536 /* Don't assume read-only, let the mount options set it
1537 * below
1539 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1541 else if (!strncmp("nfs", stfs.f_fstypename,
1542 sizeof(stfs.f_fstypename)))
1544 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1545 info->Characteristics |= FILE_REMOTE_DEVICE;
1547 else if (!strncmp("nwfs", stfs.f_fstypename,
1548 sizeof(stfs.f_fstypename)))
1550 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1551 info->Characteristics |= FILE_REMOTE_DEVICE;
1553 else if (!strncmp("procfs", stfs.f_fstypename,
1554 sizeof(stfs.f_fstypename)))
1555 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1556 else
1557 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1558 if (stfs.f_flags & MNT_RDONLY)
1559 info->Characteristics |= FILE_READ_ONLY_DEVICE;
1560 if (!(stfs.f_flags & MNT_LOCAL))
1562 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1563 info->Characteristics |= FILE_REMOTE_DEVICE;
1565 #elif defined (__APPLE__)
1566 struct statfs stfs;
1568 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1570 if (fstatfs( fd, &stfs ) < 0) break;
1572 /* stfs.f_type is reserved (always set to 0) so use IOKit */
1573 kern_return_t kernResult = KERN_FAILURE;
1574 mach_port_t masterPort;
1576 char bsdName[6]; /* disk#\0 */
1577 const char *name = stfs.f_mntfromname + strlen(_PATH_DEV);
1578 memcpy( bsdName, name, min(strlen(name)+1,sizeof(bsdName)) );
1579 bsdName[sizeof(bsdName)-1] = 0;
1581 kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
1583 if (kernResult == KERN_SUCCESS)
1585 CFMutableDictionaryRef matching = IOBSDNameMatching(masterPort, 0, bsdName);
1587 if (matching)
1589 CFMutableDictionaryRef properties;
1590 io_service_t devService = IOServiceGetMatchingService(masterPort, matching);
1592 if (IORegistryEntryCreateCFProperties(devService,
1593 &properties,
1594 kCFAllocatorDefault, 0) != KERN_SUCCESS)
1595 break;
1596 if ( CFEqual(
1597 CFDictionaryGetValue(properties, CFSTR("Removable")),
1598 kCFBooleanTrue)
1599 ) info->Characteristics |= FILE_REMOVABLE_MEDIA;
1601 if ( CFEqual(
1602 CFDictionaryGetValue(properties, CFSTR("Writable")),
1603 kCFBooleanFalse)
1604 ) info->Characteristics |= FILE_READ_ONLY_DEVICE;
1607 NB : mounted disk image (.img/.dmg) don't provide specific type
1609 CFStringRef type;
1610 if ( (type = CFDictionaryGetValue(properties, CFSTR("Type"))) )
1612 if ( CFStringCompare(type, CFSTR("CD-ROM"), 0) == kCFCompareEqualTo
1613 || CFStringCompare(type, CFSTR("DVD-ROM"), 0) == kCFCompareEqualTo
1616 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1620 if (properties)
1621 CFRelease(properties);
1624 #elif defined(sun)
1625 /* Use dkio to work out device types */
1627 # include <sys/dkio.h>
1628 # include <sys/vtoc.h>
1629 struct dk_cinfo dkinf;
1630 int retval = ioctl(fd, DKIOCINFO, &dkinf);
1631 if(retval==-1){
1632 WARN("Unable to get disk device type information - assuming a disk like device\n");
1633 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1635 switch (dkinf.dki_ctype)
1637 case DKC_CDROM:
1638 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1639 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1640 break;
1641 case DKC_NCRFLOPPY:
1642 case DKC_SMSFLOPPY:
1643 case DKC_INTEL82072:
1644 case DKC_INTEL82077:
1645 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1646 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1647 break;
1648 case DKC_MD:
1649 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1650 break;
1651 default:
1652 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1655 #else
1656 static int warned;
1657 if (!warned++) FIXME( "device info not properly supported on this platform\n" );
1658 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1659 #endif
1660 info->Characteristics |= FILE_DEVICE_IS_MOUNTED;
1662 io->Information = sizeof(*info);
1663 io->u.Status = STATUS_SUCCESS;
1665 break;
1666 case FileFsAttributeInformation:
1667 FIXME( "%p: attribute info not supported\n", handle );
1668 break;
1669 case FileFsControlInformation:
1670 FIXME( "%p: control info not supported\n", handle );
1671 break;
1672 case FileFsFullSizeInformation:
1673 FIXME( "%p: full size info not supported\n", handle );
1674 break;
1675 case FileFsObjectIdInformation:
1676 FIXME( "%p: object id info not supported\n", handle );
1677 break;
1678 case FileFsMaximumInformation:
1679 FIXME( "%p: maximum info not supported\n", handle );
1680 break;
1681 default:
1682 io->u.Status = STATUS_INVALID_PARAMETER;
1683 break;
1685 wine_server_release_fd( handle, fd );
1686 return io->u.Status;
1690 /******************************************************************
1691 * NtFlushBuffersFile (NTDLL.@)
1693 * Flush any buffered data on an open file handle.
1695 * PARAMS
1696 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1697 * IoStatusBlock [O] Receives information about the operation on return
1699 * RETURNS
1700 * Success: 0. IoStatusBlock is updated.
1701 * Failure: An NTSTATUS error code describing the error.
1703 NTSTATUS WINAPI NtFlushBuffersFile( HANDLE hFile, IO_STATUS_BLOCK* IoStatusBlock )
1705 NTSTATUS ret;
1706 HANDLE hEvent = NULL;
1708 SERVER_START_REQ( flush_file )
1710 req->handle = hFile;
1711 ret = wine_server_call( req );
1712 hEvent = reply->event;
1714 SERVER_END_REQ;
1715 if (!ret && hEvent)
1717 ret = NtWaitForSingleObject( hEvent, FALSE, NULL );
1718 NtClose( hEvent );
1720 return ret;
1723 /******************************************************************
1724 * NtLockFile (NTDLL.@)
1728 NTSTATUS WINAPI NtLockFile( HANDLE hFile, HANDLE lock_granted_event,
1729 PIO_APC_ROUTINE apc, void* apc_user,
1730 PIO_STATUS_BLOCK io_status, PLARGE_INTEGER offset,
1731 PLARGE_INTEGER count, ULONG* key, BOOLEAN dont_wait,
1732 BOOLEAN exclusive )
1734 NTSTATUS ret;
1735 HANDLE handle;
1736 BOOLEAN async;
1738 if (apc || io_status || key)
1740 FIXME("Unimplemented yet parameter\n");
1741 return STATUS_NOT_IMPLEMENTED;
1744 for (;;)
1746 SERVER_START_REQ( lock_file )
1748 req->handle = hFile;
1749 req->offset_low = offset->u.LowPart;
1750 req->offset_high = offset->u.HighPart;
1751 req->count_low = count->u.LowPart;
1752 req->count_high = count->u.HighPart;
1753 req->shared = !exclusive;
1754 req->wait = !dont_wait;
1755 ret = wine_server_call( req );
1756 handle = reply->handle;
1757 async = reply->overlapped;
1759 SERVER_END_REQ;
1760 if (ret != STATUS_PENDING)
1762 if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
1763 return ret;
1766 if (async)
1768 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1769 if (handle) NtClose( handle );
1770 return STATUS_PENDING;
1772 if (handle)
1774 NtWaitForSingleObject( handle, FALSE, NULL );
1775 NtClose( handle );
1777 else
1779 LARGE_INTEGER time;
1781 /* Unix lock conflict, sleep a bit and retry */
1782 time.QuadPart = 100 * (ULONGLONG)10000;
1783 time.QuadPart = -time.QuadPart;
1784 NtDelayExecution( FALSE, &time );
1790 /******************************************************************
1791 * NtUnlockFile (NTDLL.@)
1795 NTSTATUS WINAPI NtUnlockFile( HANDLE hFile, PIO_STATUS_BLOCK io_status,
1796 PLARGE_INTEGER offset, PLARGE_INTEGER count,
1797 PULONG key )
1799 NTSTATUS status;
1801 TRACE( "%p %lx%08lx %lx%08lx\n",
1802 hFile, offset->u.HighPart, offset->u.LowPart, count->u.HighPart, count->u.LowPart );
1804 if (io_status || key)
1806 FIXME("Unimplemented yet parameter\n");
1807 return STATUS_NOT_IMPLEMENTED;
1810 SERVER_START_REQ( unlock_file )
1812 req->handle = hFile;
1813 req->offset_low = offset->u.LowPart;
1814 req->offset_high = offset->u.HighPart;
1815 req->count_low = count->u.LowPart;
1816 req->count_high = count->u.HighPart;
1817 status = wine_server_call( req );
1819 SERVER_END_REQ;
1820 return status;
1823 /******************************************************************
1824 * NtCreateNamedPipeFile (NTDLL.@)
1828 NTSTATUS WINAPI NtCreateNamedPipeFile( PHANDLE handle, ULONG access,
1829 POBJECT_ATTRIBUTES oa, PIO_STATUS_BLOCK iosb,
1830 ULONG sharing, ULONG dispo, ULONG options,
1831 ULONG pipe_type, ULONG read_mode,
1832 ULONG completion_mode, ULONG max_inst,
1833 ULONG inbound_quota, ULONG outbound_quota,
1834 PLARGE_INTEGER timeout)
1836 NTSTATUS status;
1837 static const WCHAR leadin[] = {'\\','?','?','\\','P','I','P','E','\\'};
1839 TRACE("(%p %lx %p %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p): stub\n",
1840 handle, access, oa, iosb, sharing, dispo, options, pipe_type,
1841 read_mode, completion_mode, max_inst, inbound_quota, outbound_quota,
1842 timeout);
1844 if (oa->ObjectName->Length < sizeof(leadin) ||
1845 strncmpiW( oa->ObjectName->Buffer,
1846 leadin, sizeof(leadin)/sizeof(leadin[0]) ))
1847 return STATUS_OBJECT_NAME_INVALID;
1848 /* assume we only get relative timeout, and storable in a DWORD as ms */
1849 if (timeout->QuadPart > 0 || (timeout->QuadPart / -10000) >> 32)
1850 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout->QuadPart));
1852 SERVER_START_REQ( create_named_pipe )
1854 req->options = options; /* FIXME not used in server yet !!!! */
1855 req->flags =
1856 (pipe_type) ? NAMED_PIPE_MESSAGE_STREAM_WRITE : 0 |
1857 (read_mode) ? NAMED_PIPE_MESSAGE_STREAM_READ : 0 |
1858 (completion_mode) ? NAMED_PIPE_NONBLOCKING_MODE : 0;
1859 req->maxinstances = max_inst;
1860 req->outsize = outbound_quota;
1861 req->insize = inbound_quota;
1862 req->timeout = timeout->QuadPart / -10000;
1863 req->inherit = (oa->Attributes & OBJ_INHERIT) != 0;
1864 wine_server_add_data( req, oa->ObjectName->Buffer + 4,
1865 oa->ObjectName->Length - 4 * sizeof(WCHAR) );
1866 status = wine_server_call( req );
1867 if (!status) *handle = reply->handle;
1869 SERVER_END_REQ;
1870 return status;
1873 /******************************************************************
1874 * NtDeleteFile (NTDLL.@)
1878 NTSTATUS WINAPI NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes )
1880 NTSTATUS status;
1881 HANDLE hFile;
1882 IO_STATUS_BLOCK io;
1884 TRACE("%p\n", ObjectAttributes);
1885 status = NtCreateFile( &hFile, GENERIC_READ | GENERIC_WRITE, ObjectAttributes,
1886 &io, NULL, 0,
1887 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1888 FILE_OPEN, FILE_DELETE_ON_CLOSE, NULL, 0 );
1889 if (status == STATUS_SUCCESS) status = NtClose(hFile);
1890 return status;
1893 /******************************************************************
1894 * NtCancelIoFile (NTDLL.@)
1898 NTSTATUS WINAPI NtCancelIoFile( HANDLE hFile, PIO_STATUS_BLOCK io_status )
1900 LARGE_INTEGER timeout;
1902 TRACE("%p %p\n", hFile, io_status );
1904 SERVER_START_REQ( cancel_async )
1906 req->handle = hFile;
1907 wine_server_call( req );
1909 SERVER_END_REQ;
1910 /* Let some APC be run, so that we can run the remaining APCs on hFile
1911 * either the cancelation of the pending one, but also the execution
1912 * of the queued APC, but not yet run. This is needed to ensure proper
1913 * clean-up of allocated data.
1915 timeout.u.LowPart = timeout.u.HighPart = 0;
1916 return io_status->u.Status = NtDelayExecution( TRUE, &timeout );
1919 /******************************************************************************
1920 * NtCreateMailslotFile [NTDLL.@]
1921 * ZwCreateMailslotFile [NTDLL.@]
1923 * PARAMS
1924 * pHandle [O] pointer to receive the handle created
1925 * DesiredAccess [I] access mode (read, write, etc)
1926 * ObjectAttributes [I] fully qualified NT path of the mailslot
1927 * IoStatusBlock [O] receives completion status and other info
1928 * CreateOptions [I]
1929 * MailslotQuota [I]
1930 * MaxMessageSize [I]
1931 * TimeOut [I]
1933 * RETURNS
1934 * An NT status code
1936 NTSTATUS WINAPI NtCreateMailslotFile(PHANDLE pHandle, ULONG DesiredAccess,
1937 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK IoStatusBlock,
1938 ULONG CreateOptions, ULONG MailslotQuota, ULONG MaxMessageSize,
1939 PLARGE_INTEGER TimeOut)
1941 static const WCHAR leadin[] = {
1942 '\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
1943 NTSTATUS ret;
1945 TRACE("%p %08lx %p %p %08lx %08lx %08lx %p\n",
1946 pHandle, DesiredAccess, attr, IoStatusBlock,
1947 CreateOptions, MailslotQuota, MaxMessageSize, TimeOut);
1949 if (attr->ObjectName->Length < sizeof(leadin) ||
1950 strncmpiW( attr->ObjectName->Buffer,
1951 leadin, sizeof(leadin)/sizeof(leadin[0]) ))
1953 return STATUS_OBJECT_NAME_INVALID;
1956 SERVER_START_REQ( create_mailslot )
1958 req->max_msgsize = MaxMessageSize;
1959 req->read_timeout = TimeOut->QuadPart / -10000;
1960 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
1961 wine_server_add_data( req, attr->ObjectName->Buffer + 4,
1962 attr->ObjectName->Length - 4*sizeof(WCHAR) );
1963 ret = wine_server_call( req );
1964 if( ret == STATUS_SUCCESS )
1965 *pHandle = reply->handle;
1967 SERVER_END_REQ;
1969 return ret;