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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
30 #ifdef HAVE_LINUX_MAJOR_H
31 # include <linux/major.h>
33 #ifdef HAVE_SYS_STATVFS_H
34 # include <sys/statvfs.h>
36 #ifdef HAVE_SYS_PARAM_H
37 # include <sys/param.h>
39 #ifdef HAVE_SYS_TIME_H
40 # include <sys/time.h>
42 #ifdef HAVE_SYS_IOCTL_H
43 #include <sys/ioctl.h>
45 #ifdef HAVE_SYS_FILIO_H
46 # include <sys/filio.h>
51 #ifdef HAVE_SYS_POLL_H
54 #ifdef HAVE_SYS_SOCKET_H
55 #include <sys/socket.h>
63 #ifdef HAVE_SYS_MOUNT_H
64 # include <sys/mount.h>
66 #ifdef HAVE_SYS_STATFS_H
67 # include <sys/statfs.h>
69 #ifdef HAVE_VALGRIND_MEMCHECK_H
70 # include <valgrind/memcheck.h>
73 #define NONAMELESSUNION
74 #define NONAMELESSSTRUCT
76 #define WIN32_NO_STATUS
77 #include "wine/unicode.h"
78 #include "wine/debug.h"
79 #include "wine/server.h"
80 #include "ntdll_misc.h"
84 #include "ddk/ntddser.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
87 WINE_DECLARE_DEBUG_CHANNEL(winediag);
89 mode_t FILE_umask = 0;
91 #define SECSPERDAY 86400
92 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
95 /**************************************************************************
96 * FILE_CreateFile (internal)
99 * Parameter set fully identical with NtCreateFile
101 static NTSTATUS FILE_CreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
102 PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
103 ULONG attributes, ULONG sharing, ULONG disposition,
104 ULONG options, PVOID ea_buffer, ULONG ea_length )
106 ANSI_STRING unix_name;
109 TRACE("handle=%p access=%08x name=%s objattr=%08x root=%p sec=%p io=%p alloc_size=%p "
110 "attr=%08x sharing=%08x disp=%d options=%08x ea=%p.0x%08x\n",
111 handle, access, debugstr_us(attr->ObjectName), attr->Attributes,
112 attr->RootDirectory, attr->SecurityDescriptor, io, alloc_size,
113 attributes, sharing, disposition, options, ea_buffer, ea_length );
115 if (!attr || !attr->ObjectName) return STATUS_INVALID_PARAMETER;
117 if (alloc_size) FIXME( "alloc_size not supported\n" );
119 if (options & FILE_OPEN_BY_FILE_ID)
120 io->u.Status = file_id_to_unix_file_name( attr, &unix_name );
122 io->u.Status = nt_to_unix_file_name_attr( attr, &unix_name, disposition );
124 if (io->u.Status == STATUS_BAD_DEVICE_TYPE)
126 SERVER_START_REQ( open_file_object )
128 req->access = access;
129 req->attributes = attr->Attributes;
130 req->rootdir = wine_server_obj_handle( attr->RootDirectory );
131 req->sharing = sharing;
132 req->options = options;
133 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
134 io->u.Status = wine_server_call( req );
135 *handle = wine_server_ptr_handle( reply->handle );
138 if (io->u.Status == STATUS_SUCCESS) io->Information = FILE_OPENED;
142 if (io->u.Status == STATUS_NO_SUCH_FILE &&
143 disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
146 io->u.Status = STATUS_SUCCESS;
149 if (io->u.Status == STATUS_SUCCESS)
151 struct security_descriptor *sd;
152 struct object_attributes objattr;
154 objattr.rootdir = wine_server_obj_handle( attr->RootDirectory );
155 objattr.name_len = 0;
156 io->u.Status = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
157 if (io->u.Status != STATUS_SUCCESS)
159 RtlFreeAnsiString( &unix_name );
163 SERVER_START_REQ( create_file )
165 req->access = access;
166 req->attributes = attr->Attributes;
167 req->sharing = sharing;
168 req->create = disposition;
169 req->options = options;
170 req->attrs = attributes;
171 wine_server_add_data( req, &objattr, sizeof(objattr) );
172 if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
173 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
174 io->u.Status = wine_server_call( req );
175 *handle = wine_server_ptr_handle( reply->handle );
178 NTDLL_free_struct_sd( sd );
179 RtlFreeAnsiString( &unix_name );
181 else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), io->u.Status );
183 if (io->u.Status == STATUS_SUCCESS)
185 if (created) io->Information = FILE_CREATED;
186 else switch(disposition)
189 io->Information = FILE_SUPERSEDED;
192 io->Information = FILE_CREATED;
196 io->Information = FILE_OPENED;
199 case FILE_OVERWRITE_IF:
200 io->Information = FILE_OVERWRITTEN;
204 else if (io->u.Status == STATUS_TOO_MANY_OPENED_FILES)
207 if (!once++) ERR_(winediag)( "Too many open files, ulimit -n probably needs to be increased\n" );
213 /**************************************************************************
214 * NtOpenFile [NTDLL.@]
215 * ZwOpenFile [NTDLL.@]
220 * handle [O] Variable that receives the file handle on return
221 * access [I] Access desired by the caller to the file
222 * attr [I] Structure describing the file to be opened
223 * io [O] Receives details about the result of the operation
224 * sharing [I] Type of shared access the caller requires
225 * options [I] Options for the file open
228 * Success: 0. FileHandle and IoStatusBlock are updated.
229 * Failure: An NTSTATUS error code describing the error.
231 NTSTATUS WINAPI NtOpenFile( PHANDLE handle, ACCESS_MASK access,
232 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK io,
233 ULONG sharing, ULONG options )
235 return FILE_CreateFile( handle, access, attr, io, NULL, 0,
236 sharing, FILE_OPEN, options, NULL, 0 );
239 /**************************************************************************
240 * NtCreateFile [NTDLL.@]
241 * ZwCreateFile [NTDLL.@]
243 * Either create a new file or directory, or open an existing file, device,
244 * directory or volume.
247 * handle [O] Points to a variable which receives the file handle on return
248 * access [I] Desired access to the file
249 * attr [I] Structure describing the file
250 * io [O] Receives information about the operation on return
251 * alloc_size [I] Initial size of the file in bytes
252 * attributes [I] Attributes to create the file with
253 * sharing [I] Type of shared access the caller would like to the file
254 * disposition [I] Specifies what to do, depending on whether the file already exists
255 * options [I] Options for creating a new file
256 * ea_buffer [I] Pointer to an extended attributes buffer
257 * ea_length [I] Length of ea_buffer
260 * Success: 0. handle and io are updated.
261 * Failure: An NTSTATUS error code describing the error.
263 NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
264 PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
265 ULONG attributes, ULONG sharing, ULONG disposition,
266 ULONG options, PVOID ea_buffer, ULONG ea_length )
268 return FILE_CreateFile( handle, access, attr, io, alloc_size, attributes,
269 sharing, disposition, options, ea_buffer, ea_length );
272 /***********************************************************************
273 * Asynchronous file I/O *
285 struct async_fileio io;
287 unsigned int already;
294 struct async_fileio io;
296 unsigned int already;
298 } async_fileio_write;
301 /* callback for file I/O user APC */
302 static void WINAPI fileio_apc( void *arg, IO_STATUS_BLOCK *io, ULONG reserved )
304 struct async_fileio *async = arg;
305 if (async->apc) async->apc( async->apc_arg, io, reserved );
306 RtlFreeHeap( GetProcessHeap(), 0, async );
309 /***********************************************************************
310 * FILE_GetNtStatus(void)
312 * Retrieve the Nt Status code from errno.
313 * Try to be consistent with FILE_SetDosError().
315 NTSTATUS FILE_GetNtStatus(void)
319 TRACE( "errno = %d\n", errno );
322 case EAGAIN: return STATUS_SHARING_VIOLATION;
323 case EBADF: return STATUS_INVALID_HANDLE;
324 case EBUSY: return STATUS_DEVICE_BUSY;
325 case ENOSPC: return STATUS_DISK_FULL;
328 case EACCES: return STATUS_ACCESS_DENIED;
329 case ENOTDIR: return STATUS_OBJECT_PATH_NOT_FOUND;
330 case ENOENT: return STATUS_OBJECT_NAME_NOT_FOUND;
331 case EISDIR: return STATUS_FILE_IS_A_DIRECTORY;
333 case ENFILE: return STATUS_TOO_MANY_OPENED_FILES;
334 case EINVAL: return STATUS_INVALID_PARAMETER;
335 case ENOTEMPTY: return STATUS_DIRECTORY_NOT_EMPTY;
336 case EPIPE: return STATUS_PIPE_DISCONNECTED;
337 case EIO: return STATUS_DEVICE_NOT_READY;
339 case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
341 case ENXIO: return STATUS_NO_SUCH_DEVICE;
343 case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
344 case ECONNRESET:return STATUS_PIPE_DISCONNECTED;
345 case EFAULT: return STATUS_ACCESS_VIOLATION;
346 case ESPIPE: return STATUS_ILLEGAL_FUNCTION;
347 #ifdef ETIME /* Missing on FreeBSD */
348 case ETIME: return STATUS_IO_TIMEOUT;
350 case ENOEXEC: /* ?? */
351 case EEXIST: /* ?? */
353 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err );
354 return STATUS_UNSUCCESSFUL;
358 /***********************************************************************
359 * FILE_AsyncReadService (INTERNAL)
361 static NTSTATUS FILE_AsyncReadService(void *user, PIO_STATUS_BLOCK iosb, NTSTATUS status, void **apc)
363 async_fileio_read *fileio = user;
364 int fd, needs_close, result;
368 case STATUS_ALERTED: /* got some new data */
369 /* check to see if the data is ready (non-blocking) */
370 if ((status = server_get_unix_fd( fileio->io.handle, FILE_READ_DATA, &fd,
371 &needs_close, NULL, NULL )))
374 result = read(fd, &fileio->buffer[fileio->already], fileio->count - fileio->already);
375 if (needs_close) close( fd );
379 if (errno == EAGAIN || errno == EINTR)
380 status = STATUS_PENDING;
381 else /* check to see if the transfer is complete */
382 status = FILE_GetNtStatus();
384 else if (result == 0)
386 status = fileio->already ? STATUS_SUCCESS : STATUS_PIPE_BROKEN;
390 fileio->already += result;
391 if (fileio->already >= fileio->count || fileio->avail_mode)
392 status = STATUS_SUCCESS;
395 /* if we only have to read the available data, and none is available,
396 * simply cancel the request. If data was available, it has been read
397 * while in by previous call (NtDelayExecution)
399 status = (fileio->avail_mode) ? STATUS_SUCCESS : STATUS_PENDING;
405 case STATUS_IO_TIMEOUT:
406 if (fileio->already) status = STATUS_SUCCESS;
409 if (status != STATUS_PENDING)
411 iosb->u.Status = status;
412 iosb->Information = fileio->already;
420 int interval; /* max interval between two bytes */
421 int total; /* total timeout for the whole operation */
422 int end_time; /* absolute time of end of operation */
425 /* retrieve the I/O timeouts to use for a given handle */
426 static NTSTATUS get_io_timeouts( HANDLE handle, enum server_fd_type type, ULONG count, BOOL is_read,
427 struct io_timeouts *timeouts )
429 NTSTATUS status = STATUS_SUCCESS;
431 timeouts->interval = timeouts->total = -1;
437 /* GetCommTimeouts */
441 status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io,
442 IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) );
447 if (st.ReadIntervalTimeout)
448 timeouts->interval = st.ReadIntervalTimeout;
450 if (st.ReadTotalTimeoutMultiplier || st.ReadTotalTimeoutConstant)
452 timeouts->total = st.ReadTotalTimeoutConstant;
453 if (st.ReadTotalTimeoutMultiplier != MAXDWORD)
454 timeouts->total += count * st.ReadTotalTimeoutMultiplier;
456 else if (st.ReadIntervalTimeout == MAXDWORD)
457 timeouts->interval = timeouts->total = 0;
461 if (st.WriteTotalTimeoutMultiplier || st.WriteTotalTimeoutConstant)
463 timeouts->total = st.WriteTotalTimeoutConstant;
464 if (st.WriteTotalTimeoutMultiplier != MAXDWORD)
465 timeouts->total += count * st.WriteTotalTimeoutMultiplier;
470 case FD_TYPE_MAILSLOT:
473 timeouts->interval = 0; /* return as soon as we got something */
474 SERVER_START_REQ( set_mailslot_info )
476 req->handle = wine_server_obj_handle( handle );
478 if (!(status = wine_server_call( req )) &&
479 reply->read_timeout != TIMEOUT_INFINITE)
480 timeouts->total = reply->read_timeout / -10000;
488 if (is_read) timeouts->interval = 0; /* return as soon as we got something */
493 if (timeouts->total != -1) timeouts->end_time = NtGetTickCount() + timeouts->total;
494 return STATUS_SUCCESS;
498 /* retrieve the timeout for the next wait, in milliseconds */
499 static inline int get_next_io_timeout( const struct io_timeouts *timeouts, ULONG already )
503 if (timeouts->total != -1)
505 ret = timeouts->end_time - NtGetTickCount();
506 if (ret < 0) ret = 0;
508 if (already && timeouts->interval != -1)
510 if (ret == -1 || ret > timeouts->interval) ret = timeouts->interval;
516 /* retrieve the avail_mode flag for async reads */
517 static NTSTATUS get_io_avail_mode( HANDLE handle, enum server_fd_type type, BOOL *avail_mode )
519 NTSTATUS status = STATUS_SUCCESS;
525 /* GetCommTimeouts */
529 status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io,
530 IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) );
532 *avail_mode = (!st.ReadTotalTimeoutMultiplier &&
533 !st.ReadTotalTimeoutConstant &&
534 st.ReadIntervalTimeout == MAXDWORD);
537 case FD_TYPE_MAILSLOT:
551 /******************************************************************************
552 * NtReadFile [NTDLL.@]
553 * ZwReadFile [NTDLL.@]
555 * Read from an open file handle.
558 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
559 * Event [I] Event to signal upon completion (or NULL)
560 * ApcRoutine [I] Callback to call upon completion (or NULL)
561 * ApcContext [I] Context for ApcRoutine (or NULL)
562 * IoStatusBlock [O] Receives information about the operation on return
563 * Buffer [O] Destination for the data read
564 * Length [I] Size of Buffer
565 * ByteOffset [O] Destination for the new file pointer position (or NULL)
566 * Key [O] Function unknown (may be NULL)
569 * Success: 0. IoStatusBlock is updated, and the Information member contains
570 * The number of bytes read.
571 * Failure: An NTSTATUS error code describing the error.
573 NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
574 PIO_APC_ROUTINE apc, void* apc_user,
575 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
576 PLARGE_INTEGER offset, PULONG key)
578 int result, unix_handle, needs_close, timeout_init_done = 0;
579 unsigned int options;
580 struct io_timeouts timeouts;
583 enum server_fd_type type;
584 ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
585 BOOL send_completion = FALSE;
587 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
588 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
590 if (!io_status) return STATUS_ACCESS_VIOLATION;
592 status = server_get_unix_fd( hFile, FILE_READ_DATA, &unix_handle,
593 &needs_close, &type, &options );
594 if (status) return status;
596 if (!virtual_check_buffer_for_write( buffer, length ))
598 status = STATUS_ACCESS_VIOLATION;
602 if (type == FD_TYPE_FILE && offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */ )
604 /* async I/O doesn't make sense on regular files */
605 while ((result = pread( unix_handle, buffer, length, offset->QuadPart )) == -1)
609 status = FILE_GetNtStatus();
613 if (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT))
614 /* update file pointer position */
615 lseek( unix_handle, offset->QuadPart + result, SEEK_SET );
618 status = total ? STATUS_SUCCESS : STATUS_END_OF_FILE;
624 if ((result = read( unix_handle, (char *)buffer + total, length - total )) >= 0)
627 if (!result || total == length)
631 status = STATUS_SUCCESS;
638 status = STATUS_END_OF_FILE;
643 status = STATUS_PIPE_BROKEN;
647 else if (type == FD_TYPE_FILE) continue; /* no async I/O on regular files */
649 else if (errno != EAGAIN)
651 if (errno == EINTR) continue;
652 if (!total) status = FILE_GetNtStatus();
656 if (!(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)))
658 async_fileio_read *fileio;
661 if ((status = get_io_avail_mode( hFile, type, &avail_mode )))
663 if (total && avail_mode)
665 status = STATUS_SUCCESS;
669 if (!(fileio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*fileio))))
671 status = STATUS_NO_MEMORY;
674 fileio->io.handle = hFile;
675 fileio->io.apc = apc;
676 fileio->io.apc_arg = apc_user;
677 fileio->already = total;
678 fileio->count = length;
679 fileio->buffer = buffer;
680 fileio->avail_mode = avail_mode;
682 SERVER_START_REQ( register_async )
684 req->type = ASYNC_TYPE_READ;
686 req->async.handle = wine_server_obj_handle( hFile );
687 req->async.event = wine_server_obj_handle( hEvent );
688 req->async.callback = wine_server_client_ptr( FILE_AsyncReadService );
689 req->async.iosb = wine_server_client_ptr( io_status );
690 req->async.arg = wine_server_client_ptr( fileio );
691 req->async.cvalue = cvalue;
692 status = wine_server_call( req );
696 if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, fileio );
699 else /* synchronous read, wait for the fd to become ready */
704 if (!timeout_init_done)
706 timeout_init_done = 1;
707 if ((status = get_io_timeouts( hFile, type, length, TRUE, &timeouts )))
709 if (hEvent) NtResetEvent( hEvent, NULL );
711 timeout = get_next_io_timeout( &timeouts, total );
713 pfd.fd = unix_handle;
716 if (!timeout || !(ret = poll( &pfd, 1, timeout )))
718 if (total) /* return with what we got so far */
719 status = STATUS_SUCCESS;
721 status = (type == FD_TYPE_MAILSLOT) ? STATUS_IO_TIMEOUT : STATUS_TIMEOUT;
724 if (ret == -1 && errno != EINTR)
726 status = FILE_GetNtStatus();
729 /* will now restart the read */
734 send_completion = cvalue != 0;
737 if (needs_close) close( unix_handle );
738 if (status == STATUS_SUCCESS)
740 io_status->u.Status = status;
741 io_status->Information = total;
742 TRACE("= SUCCESS (%u)\n", total);
743 if (hEvent) NtSetEvent( hEvent, NULL );
744 if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
745 (ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
749 TRACE("= 0x%08x\n", status);
750 if (status != STATUS_PENDING && hEvent) NtResetEvent( hEvent, NULL );
753 if (send_completion) NTDLL_AddCompletion( hFile, cvalue, status, total );
759 /******************************************************************************
760 * NtReadFileScatter [NTDLL.@]
761 * ZwReadFileScatter [NTDLL.@]
763 NTSTATUS WINAPI NtReadFileScatter( HANDLE file, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
764 PIO_STATUS_BLOCK io_status, FILE_SEGMENT_ELEMENT *segments,
765 ULONG length, PLARGE_INTEGER offset, PULONG key )
767 size_t page_size = getpagesize();
768 int result, unix_handle, needs_close;
769 unsigned int options;
771 ULONG pos = 0, total = 0;
772 enum server_fd_type type;
773 ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
774 BOOL send_completion = FALSE;
776 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
777 file, event, apc, apc_user, io_status, segments, length, offset, key);
779 if (length % page_size) return STATUS_INVALID_PARAMETER;
780 if (!io_status) return STATUS_ACCESS_VIOLATION;
782 status = server_get_unix_fd( file, FILE_READ_DATA, &unix_handle,
783 &needs_close, &type, &options );
784 if (status) return status;
786 if ((type != FD_TYPE_FILE) ||
787 (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) ||
788 !(options & FILE_NO_INTERMEDIATE_BUFFERING))
790 status = STATUS_INVALID_PARAMETER;
796 if (offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */)
797 result = pread( unix_handle, (char *)segments->Buffer + pos,
798 page_size - pos, offset->QuadPart + total );
800 result = read( unix_handle, (char *)segments->Buffer + pos, page_size - pos );
804 if (errno == EINTR) continue;
805 status = FILE_GetNtStatus();
810 status = STATUS_END_OF_FILE;
815 if ((pos += result) == page_size)
822 send_completion = cvalue != 0;
825 if (needs_close) close( unix_handle );
826 if (status == STATUS_SUCCESS)
828 io_status->u.Status = status;
829 io_status->Information = total;
830 TRACE("= SUCCESS (%u)\n", total);
831 if (event) NtSetEvent( event, NULL );
832 if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
833 (ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
837 TRACE("= 0x%08x\n", status);
838 if (status != STATUS_PENDING && event) NtResetEvent( event, NULL );
841 if (send_completion) NTDLL_AddCompletion( file, cvalue, status, total );
847 /***********************************************************************
848 * FILE_AsyncWriteService (INTERNAL)
850 static NTSTATUS FILE_AsyncWriteService(void *user, IO_STATUS_BLOCK *iosb, NTSTATUS status, void **apc)
852 async_fileio_write *fileio = user;
853 int result, fd, needs_close;
854 enum server_fd_type type;
859 /* write some data (non-blocking) */
860 if ((status = server_get_unix_fd( fileio->io.handle, FILE_WRITE_DATA, &fd,
861 &needs_close, &type, NULL )))
864 if (!fileio->count && (type == FD_TYPE_MAILSLOT || type == FD_TYPE_PIPE || type == FD_TYPE_SOCKET))
865 result = send( fd, fileio->buffer, 0, 0 );
867 result = write( fd, &fileio->buffer[fileio->already], fileio->count - fileio->already );
869 if (needs_close) close( fd );
873 if (errno == EAGAIN || errno == EINTR) status = STATUS_PENDING;
874 else status = FILE_GetNtStatus();
878 fileio->already += result;
879 status = (fileio->already < fileio->count) ? STATUS_PENDING : STATUS_SUCCESS;
884 case STATUS_IO_TIMEOUT:
885 if (fileio->already) status = STATUS_SUCCESS;
888 if (status != STATUS_PENDING)
890 iosb->u.Status = status;
891 iosb->Information = fileio->already;
897 /******************************************************************************
898 * NtWriteFile [NTDLL.@]
899 * ZwWriteFile [NTDLL.@]
901 * Write to an open file handle.
904 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
905 * Event [I] Event to signal upon completion (or NULL)
906 * ApcRoutine [I] Callback to call upon completion (or NULL)
907 * ApcContext [I] Context for ApcRoutine (or NULL)
908 * IoStatusBlock [O] Receives information about the operation on return
909 * Buffer [I] Source for the data to write
910 * Length [I] Size of Buffer
911 * ByteOffset [O] Destination for the new file pointer position (or NULL)
912 * Key [O] Function unknown (may be NULL)
915 * Success: 0. IoStatusBlock is updated, and the Information member contains
916 * The number of bytes written.
917 * Failure: An NTSTATUS error code describing the error.
919 NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
920 PIO_APC_ROUTINE apc, void* apc_user,
921 PIO_STATUS_BLOCK io_status,
922 const void* buffer, ULONG length,
923 PLARGE_INTEGER offset, PULONG key)
925 int result, unix_handle, needs_close, timeout_init_done = 0;
926 unsigned int options;
927 struct io_timeouts timeouts;
930 enum server_fd_type type;
931 ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
932 BOOL send_completion = FALSE;
934 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)!\n",
935 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
937 if (!io_status) return STATUS_ACCESS_VIOLATION;
939 status = server_get_unix_fd( hFile, FILE_WRITE_DATA, &unix_handle,
940 &needs_close, &type, &options );
941 if (status) return status;
943 if (!virtual_check_buffer_for_read( buffer, length ))
945 status = STATUS_INVALID_USER_BUFFER;
949 if (type == FD_TYPE_FILE && offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */ )
951 /* async I/O doesn't make sense on regular files */
952 while ((result = pwrite( unix_handle, buffer, length, offset->QuadPart )) == -1)
956 if (errno == EFAULT) status = STATUS_INVALID_USER_BUFFER;
957 else status = FILE_GetNtStatus();
962 if (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT))
963 /* update file pointer position */
964 lseek( unix_handle, offset->QuadPart + result, SEEK_SET );
967 status = STATUS_SUCCESS;
973 /* zero-length writes on sockets may not work with plain write(2) */
974 if (!length && (type == FD_TYPE_MAILSLOT || type == FD_TYPE_PIPE || type == FD_TYPE_SOCKET))
975 result = send( unix_handle, buffer, 0, 0 );
977 result = write( unix_handle, (const char *)buffer + total, length - total );
984 status = STATUS_SUCCESS;
987 if (type == FD_TYPE_FILE) continue; /* no async I/O on regular files */
989 else if (errno != EAGAIN)
991 if (errno == EINTR) continue;
994 if (errno == EFAULT) status = STATUS_INVALID_USER_BUFFER;
995 else status = FILE_GetNtStatus();
1000 if (!(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)))
1002 async_fileio_write *fileio;
1004 if (!(fileio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*fileio))))
1006 status = STATUS_NO_MEMORY;
1009 fileio->io.handle = hFile;
1010 fileio->io.apc = apc;
1011 fileio->io.apc_arg = apc_user;
1012 fileio->already = total;
1013 fileio->count = length;
1014 fileio->buffer = buffer;
1016 SERVER_START_REQ( register_async )
1018 req->type = ASYNC_TYPE_WRITE;
1019 req->count = length;
1020 req->async.handle = wine_server_obj_handle( hFile );
1021 req->async.event = wine_server_obj_handle( hEvent );
1022 req->async.callback = wine_server_client_ptr( FILE_AsyncWriteService );
1023 req->async.iosb = wine_server_client_ptr( io_status );
1024 req->async.arg = wine_server_client_ptr( fileio );
1025 req->async.cvalue = cvalue;
1026 status = wine_server_call( req );
1030 if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, fileio );
1033 else /* synchronous write, wait for the fd to become ready */
1038 if (!timeout_init_done)
1040 timeout_init_done = 1;
1041 if ((status = get_io_timeouts( hFile, type, length, FALSE, &timeouts )))
1043 if (hEvent) NtResetEvent( hEvent, NULL );
1045 timeout = get_next_io_timeout( &timeouts, total );
1047 pfd.fd = unix_handle;
1048 pfd.events = POLLOUT;
1050 if (!timeout || !(ret = poll( &pfd, 1, timeout )))
1052 /* return with what we got so far */
1053 status = total ? STATUS_SUCCESS : STATUS_TIMEOUT;
1056 if (ret == -1 && errno != EINTR)
1058 status = FILE_GetNtStatus();
1061 /* will now restart the write */
1066 send_completion = cvalue != 0;
1069 if (needs_close) close( unix_handle );
1070 if (status == STATUS_SUCCESS)
1072 io_status->u.Status = status;
1073 io_status->Information = total;
1074 TRACE("= SUCCESS (%u)\n", total);
1075 if (hEvent) NtSetEvent( hEvent, NULL );
1076 if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
1077 (ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
1081 TRACE("= 0x%08x\n", status);
1082 if (status != STATUS_PENDING && hEvent) NtResetEvent( hEvent, NULL );
1085 if (send_completion) NTDLL_AddCompletion( hFile, cvalue, status, total );
1091 /******************************************************************************
1092 * NtWriteFileGather [NTDLL.@]
1093 * ZwWriteFileGather [NTDLL.@]
1095 NTSTATUS WINAPI NtWriteFileGather( HANDLE file, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
1096 PIO_STATUS_BLOCK io_status, FILE_SEGMENT_ELEMENT *segments,
1097 ULONG length, PLARGE_INTEGER offset, PULONG key )
1099 size_t page_size = getpagesize();
1100 int result, unix_handle, needs_close;
1101 unsigned int options;
1103 ULONG pos = 0, total = 0;
1104 enum server_fd_type type;
1105 ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
1106 BOOL send_completion = FALSE;
1108 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
1109 file, event, apc, apc_user, io_status, segments, length, offset, key);
1111 if (length % page_size) return STATUS_INVALID_PARAMETER;
1112 if (!io_status) return STATUS_ACCESS_VIOLATION;
1114 status = server_get_unix_fd( file, FILE_WRITE_DATA, &unix_handle,
1115 &needs_close, &type, &options );
1116 if (status) return status;
1118 if ((type != FD_TYPE_FILE) ||
1119 (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) ||
1120 !(options & FILE_NO_INTERMEDIATE_BUFFERING))
1122 status = STATUS_INVALID_PARAMETER;
1128 if (offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */)
1129 result = pwrite( unix_handle, (char *)segments->Buffer + pos,
1130 page_size - pos, offset->QuadPart + total );
1132 result = write( unix_handle, (char *)segments->Buffer + pos, page_size - pos );
1136 if (errno == EINTR) continue;
1137 if (errno == EFAULT)
1139 status = STATUS_INVALID_USER_BUFFER;
1142 status = FILE_GetNtStatus();
1147 status = STATUS_DISK_FULL;
1152 if ((pos += result) == page_size)
1159 send_completion = cvalue != 0;
1162 if (needs_close) close( unix_handle );
1163 if (status == STATUS_SUCCESS)
1165 io_status->u.Status = status;
1166 io_status->Information = total;
1167 TRACE("= SUCCESS (%u)\n", total);
1168 if (event) NtSetEvent( event, NULL );
1169 if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
1170 (ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
1174 TRACE("= 0x%08x\n", status);
1175 if (status != STATUS_PENDING && event) NtResetEvent( event, NULL );
1178 if (send_completion) NTDLL_AddCompletion( file, cvalue, status, total );
1186 HANDLE handle; /* handle to the device */
1187 HANDLE event; /* async event */
1188 void *buffer; /* buffer for output */
1189 ULONG size; /* size of buffer */
1190 PIO_APC_ROUTINE apc; /* user apc params */
1194 /* callback for ioctl user APC */
1195 static void WINAPI ioctl_apc( void *arg, IO_STATUS_BLOCK *io, ULONG reserved )
1197 struct async_ioctl *async = arg;
1198 if (async->apc) async->apc( async->apc_arg, io, reserved );
1199 RtlFreeHeap( GetProcessHeap(), 0, async );
1202 /* callback for ioctl async I/O completion */
1203 static NTSTATUS ioctl_completion( void *arg, IO_STATUS_BLOCK *io, NTSTATUS status, void **apc )
1205 struct async_ioctl *async = arg;
1207 if (status == STATUS_ALERTED)
1209 SERVER_START_REQ( get_ioctl_result )
1211 req->handle = wine_server_obj_handle( async->handle );
1212 req->user_arg = wine_server_client_ptr( async );
1213 wine_server_set_reply( req, async->buffer, async->size );
1214 status = wine_server_call( req );
1215 if (status != STATUS_PENDING) io->Information = wine_server_reply_size( reply );
1219 if (status != STATUS_PENDING)
1221 io->u.Status = status;
1222 if (async->apc || async->event) *apc = ioctl_apc;
1227 /* do a ioctl call through the server */
1228 static NTSTATUS server_ioctl_file( HANDLE handle, HANDLE event,
1229 PIO_APC_ROUTINE apc, PVOID apc_context,
1230 IO_STATUS_BLOCK *io, ULONG code,
1231 const void *in_buffer, ULONG in_size,
1232 PVOID out_buffer, ULONG out_size )
1234 struct async_ioctl *async;
1238 ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_context;
1240 if (!(async = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*async) )))
1241 return STATUS_NO_MEMORY;
1242 async->handle = handle;
1243 async->event = event;
1244 async->buffer = out_buffer;
1245 async->size = out_size;
1247 async->apc_arg = apc_context;
1249 SERVER_START_REQ( ioctl )
1252 req->blocking = !apc && !event && !cvalue;
1253 req->async.handle = wine_server_obj_handle( handle );
1254 req->async.callback = wine_server_client_ptr( ioctl_completion );
1255 req->async.iosb = wine_server_client_ptr( io );
1256 req->async.arg = wine_server_client_ptr( async );
1257 req->async.event = wine_server_obj_handle( event );
1258 req->async.cvalue = cvalue;
1259 wine_server_add_data( req, in_buffer, in_size );
1260 wine_server_set_reply( req, out_buffer, out_size );
1261 status = wine_server_call( req );
1262 wait_handle = wine_server_ptr_handle( reply->wait );
1263 options = reply->options;
1264 if (status != STATUS_PENDING) io->Information = wine_server_reply_size( reply );
1268 if (status == STATUS_NOT_SUPPORTED)
1269 FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
1270 code, code >> 16, (code >> 14) & 3, (code >> 2) & 0xfff, code & 3);
1272 if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, async );
1276 NtWaitForSingleObject( wait_handle, (options & FILE_SYNCHRONOUS_IO_ALERT), NULL );
1277 status = io->u.Status;
1278 NtClose( wait_handle );
1279 RtlFreeHeap( GetProcessHeap(), 0, async );
1285 /* Tell Valgrind to ignore any holes in structs we will be passing to the
1287 static void ignore_server_ioctl_struct_holes (ULONG code, const void *in_buffer,
1290 #ifdef VALGRIND_MAKE_MEM_DEFINED
1291 # define IGNORE_STRUCT_HOLE(buf, size, t, f1, f2) \
1293 if (FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1) < FIELD_OFFSET(t, f2)) \
1294 if ((size) >= FIELD_OFFSET(t, f2)) \
1295 VALGRIND_MAKE_MEM_DEFINED( \
1296 (const char *)(buf) + FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1), \
1297 FIELD_OFFSET(t, f2) - FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1)); \
1302 case FSCTL_PIPE_WAIT:
1303 IGNORE_STRUCT_HOLE(in_buffer, in_size, FILE_PIPE_WAIT_FOR_BUFFER, TimeoutSpecified, Name);
1310 /**************************************************************************
1311 * NtDeviceIoControlFile [NTDLL.@]
1312 * ZwDeviceIoControlFile [NTDLL.@]
1314 * Perform an I/O control operation on an open file handle.
1317 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1318 * event [I] Event to signal upon completion (or NULL)
1319 * apc [I] Callback to call upon completion (or NULL)
1320 * apc_context [I] Context for ApcRoutine (or NULL)
1321 * io [O] Receives information about the operation on return
1322 * code [I] Control code for the operation to perform
1323 * in_buffer [I] Source for any input data required (or NULL)
1324 * in_size [I] Size of InputBuffer
1325 * out_buffer [O] Source for any output data returned (or NULL)
1326 * out_size [I] Size of OutputBuffer
1329 * Success: 0. IoStatusBlock is updated.
1330 * Failure: An NTSTATUS error code describing the error.
1332 NTSTATUS WINAPI NtDeviceIoControlFile(HANDLE handle, HANDLE event,
1333 PIO_APC_ROUTINE apc, PVOID apc_context,
1334 PIO_STATUS_BLOCK io, ULONG code,
1335 PVOID in_buffer, ULONG in_size,
1336 PVOID out_buffer, ULONG out_size)
1338 ULONG device = (code >> 16);
1339 NTSTATUS status = STATUS_NOT_SUPPORTED;
1341 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
1342 handle, event, apc, apc_context, io, code,
1343 in_buffer, in_size, out_buffer, out_size);
1347 case FILE_DEVICE_DISK:
1348 case FILE_DEVICE_CD_ROM:
1349 case FILE_DEVICE_DVD:
1350 case FILE_DEVICE_CONTROLLER:
1351 case FILE_DEVICE_MASS_STORAGE:
1352 status = CDROM_DeviceIoControl(handle, event, apc, apc_context, io, code,
1353 in_buffer, in_size, out_buffer, out_size);
1355 case FILE_DEVICE_SERIAL_PORT:
1356 status = COMM_DeviceIoControl(handle, event, apc, apc_context, io, code,
1357 in_buffer, in_size, out_buffer, out_size);
1359 case FILE_DEVICE_TAPE:
1360 status = TAPE_DeviceIoControl(handle, event, apc, apc_context, io, code,
1361 in_buffer, in_size, out_buffer, out_size);
1365 if (status == STATUS_NOT_SUPPORTED || status == STATUS_BAD_DEVICE_TYPE)
1366 status = server_ioctl_file( handle, event, apc, apc_context, io, code,
1367 in_buffer, in_size, out_buffer, out_size );
1369 if (status != STATUS_PENDING) io->u.Status = status;
1374 /**************************************************************************
1375 * NtFsControlFile [NTDLL.@]
1376 * ZwFsControlFile [NTDLL.@]
1378 * Perform a file system control operation on an open file handle.
1381 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1382 * event [I] Event to signal upon completion (or NULL)
1383 * apc [I] Callback to call upon completion (or NULL)
1384 * apc_context [I] Context for ApcRoutine (or NULL)
1385 * io [O] Receives information about the operation on return
1386 * code [I] Control code for the operation to perform
1387 * in_buffer [I] Source for any input data required (or NULL)
1388 * in_size [I] Size of InputBuffer
1389 * out_buffer [O] Source for any output data returned (or NULL)
1390 * out_size [I] Size of OutputBuffer
1393 * Success: 0. IoStatusBlock is updated.
1394 * Failure: An NTSTATUS error code describing the error.
1396 NTSTATUS WINAPI NtFsControlFile(HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc,
1397 PVOID apc_context, PIO_STATUS_BLOCK io, ULONG code,
1398 PVOID in_buffer, ULONG in_size, PVOID out_buffer, ULONG out_size)
1402 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
1403 handle, event, apc, apc_context, io, code,
1404 in_buffer, in_size, out_buffer, out_size);
1406 if (!io) return STATUS_INVALID_PARAMETER;
1408 ignore_server_ioctl_struct_holes( code, in_buffer, in_size );
1412 case FSCTL_DISMOUNT_VOLUME:
1413 status = server_ioctl_file( handle, event, apc, apc_context, io, code,
1414 in_buffer, in_size, out_buffer, out_size );
1415 if (!status) status = DIR_unmount_device( handle );
1418 case FSCTL_PIPE_PEEK:
1420 FILE_PIPE_PEEK_BUFFER *buffer = out_buffer;
1421 int avail = 0, fd, needs_close;
1423 if (out_size < FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data ))
1425 status = STATUS_INFO_LENGTH_MISMATCH;
1429 if ((status = server_get_unix_fd( handle, FILE_READ_DATA, &fd, &needs_close, NULL, NULL )))
1433 if (ioctl( fd, FIONREAD, &avail ) != 0)
1435 TRACE("FIONREAD failed reason: %s\n",strerror(errno));
1436 if (needs_close) close( fd );
1437 status = FILE_GetNtStatus();
1441 if (!avail) /* check for closed pipe */
1443 struct pollfd pollfd;
1447 pollfd.events = POLLIN;
1449 ret = poll( &pollfd, 1, 0 );
1450 if (ret == -1 || (ret == 1 && (pollfd.revents & (POLLHUP|POLLERR))))
1452 if (needs_close) close( fd );
1453 status = STATUS_PIPE_BROKEN;
1457 buffer->NamedPipeState = 0; /* FIXME */
1458 buffer->ReadDataAvailable = avail;
1459 buffer->NumberOfMessages = 0; /* FIXME */
1460 buffer->MessageLength = 0; /* FIXME */
1461 io->Information = FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data );
1462 status = STATUS_SUCCESS;
1465 ULONG data_size = out_size - FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data );
1468 int res = recv( fd, buffer->Data, data_size, MSG_PEEK );
1469 if (res >= 0) io->Information += res;
1472 if (needs_close) close( fd );
1476 case FSCTL_PIPE_DISCONNECT:
1477 status = server_ioctl_file( handle, event, apc, apc_context, io, code,
1478 in_buffer, in_size, out_buffer, out_size );
1481 int fd = server_remove_fd_from_cache( handle );
1482 if (fd != -1) close( fd );
1486 case FSCTL_PIPE_IMPERSONATE:
1487 FIXME("FSCTL_PIPE_IMPERSONATE: impersonating self\n");
1488 status = RtlImpersonateSelf( SecurityImpersonation );
1491 case FSCTL_LOCK_VOLUME:
1492 case FSCTL_UNLOCK_VOLUME:
1493 FIXME("stub! return success - Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
1494 code, code >> 16, (code >> 14) & 3, (code >> 2) & 0xfff, code & 3);
1495 status = STATUS_SUCCESS;
1498 case FSCTL_GET_RETRIEVAL_POINTERS:
1500 RETRIEVAL_POINTERS_BUFFER *buffer = (RETRIEVAL_POINTERS_BUFFER *)out_buffer;
1502 FIXME("stub: FSCTL_GET_RETRIEVAL_POINTERS\n");
1504 if (out_size >= sizeof(RETRIEVAL_POINTERS_BUFFER))
1506 buffer->ExtentCount = 1;
1507 buffer->StartingVcn.QuadPart = 1;
1508 buffer->Extents[0].NextVcn.QuadPart = 0;
1509 buffer->Extents[0].Lcn.QuadPart = 0;
1510 io->Information = sizeof(RETRIEVAL_POINTERS_BUFFER);
1511 status = STATUS_SUCCESS;
1515 io->Information = 0;
1516 status = STATUS_BUFFER_TOO_SMALL;
1520 case FSCTL_PIPE_LISTEN:
1521 case FSCTL_PIPE_WAIT:
1523 status = server_ioctl_file( handle, event, apc, apc_context, io, code,
1524 in_buffer, in_size, out_buffer, out_size );
1528 if (status != STATUS_PENDING) io->u.Status = status;
1532 /******************************************************************************
1533 * NtSetVolumeInformationFile [NTDLL.@]
1534 * ZwSetVolumeInformationFile [NTDLL.@]
1536 * Set volume information for an open file handle.
1539 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1540 * IoStatusBlock [O] Receives information about the operation on return
1541 * FsInformation [I] Source for volume information
1542 * Length [I] Size of FsInformation
1543 * FsInformationClass [I] Type of volume information to set
1546 * Success: 0. IoStatusBlock is updated.
1547 * Failure: An NTSTATUS error code describing the error.
1549 NTSTATUS WINAPI NtSetVolumeInformationFile(
1550 IN HANDLE FileHandle,
1551 PIO_STATUS_BLOCK IoStatusBlock,
1552 PVOID FsInformation,
1554 FS_INFORMATION_CLASS FsInformationClass)
1556 FIXME("(%p,%p,%p,0x%08x,0x%08x) stub\n",
1557 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
1561 static NTSTATUS set_file_times( int fd, const LARGE_INTEGER *mtime, const LARGE_INTEGER *atime )
1563 NTSTATUS status = STATUS_SUCCESS;
1565 #ifdef HAVE_FUTIMENS
1566 struct timespec tv[2];
1568 tv[0].tv_sec = tv[1].tv_sec = 0;
1569 tv[0].tv_nsec = tv[1].tv_nsec = UTIME_OMIT;
1570 if (atime->QuadPart)
1572 tv[0].tv_sec = atime->QuadPart / 10000000 - SECS_1601_TO_1970;
1573 tv[0].tv_nsec = (atime->QuadPart % 10000000) * 100;
1575 if (mtime->QuadPart)
1577 tv[1].tv_sec = mtime->QuadPart / 10000000 - SECS_1601_TO_1970;
1578 tv[1].tv_nsec = (mtime->QuadPart % 10000000) * 100;
1580 if (futimens( fd, tv ) == -1) status = FILE_GetNtStatus();
1582 #elif defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT)
1583 struct timeval tv[2];
1586 if (!atime->QuadPart || !mtime->QuadPart)
1589 tv[0].tv_sec = tv[0].tv_usec = 0;
1590 tv[1].tv_sec = tv[1].tv_usec = 0;
1591 if (!fstat( fd, &st ))
1593 tv[0].tv_sec = st.st_atime;
1594 tv[1].tv_sec = st.st_mtime;
1595 #ifdef HAVE_STRUCT_STAT_ST_ATIM
1596 tv[0].tv_usec = st.st_atim.tv_nsec / 1000;
1598 #ifdef HAVE_STRUCT_STAT_ST_MTIM
1599 tv[1].tv_usec = st.st_mtim.tv_nsec / 1000;
1603 if (atime->QuadPart)
1605 tv[0].tv_sec = atime->QuadPart / 10000000 - SECS_1601_TO_1970;
1606 tv[0].tv_usec = (atime->QuadPart % 10000000) / 10;
1608 if (mtime->QuadPart)
1610 tv[1].tv_sec = mtime->QuadPart / 10000000 - SECS_1601_TO_1970;
1611 tv[1].tv_usec = (mtime->QuadPart % 10000000) / 10;
1614 if (futimes( fd, tv ) == -1) status = FILE_GetNtStatus();
1615 #elif defined(HAVE_FUTIMESAT)
1616 if (futimesat( fd, NULL, tv ) == -1) status = FILE_GetNtStatus();
1619 #else /* HAVE_FUTIMES || HAVE_FUTIMESAT */
1620 FIXME( "setting file times not supported\n" );
1621 status = STATUS_NOT_IMPLEMENTED;
1626 static inline void get_file_times( const struct stat *st, LARGE_INTEGER *mtime, LARGE_INTEGER *ctime,
1627 LARGE_INTEGER *atime, LARGE_INTEGER *creation )
1629 RtlSecondsSince1970ToTime( st->st_mtime, mtime );
1630 RtlSecondsSince1970ToTime( st->st_ctime, ctime );
1631 RtlSecondsSince1970ToTime( st->st_atime, atime );
1632 #ifdef HAVE_STRUCT_STAT_ST_MTIM
1633 mtime->QuadPart += st->st_mtim.tv_nsec / 100;
1635 #ifdef HAVE_STRUCT_STAT_ST_CTIM
1636 ctime->QuadPart += st->st_ctim.tv_nsec / 100;
1638 #ifdef HAVE_STRUCT_STAT_ST_ATIM
1639 atime->QuadPart += st->st_atim.tv_nsec / 100;
1644 /* fill in the file information that depends on the stat info */
1645 NTSTATUS fill_stat_info( const struct stat *st, void *ptr, FILE_INFORMATION_CLASS class )
1649 case FileBasicInformation:
1651 FILE_BASIC_INFORMATION *info = ptr;
1653 get_file_times( st, &info->LastWriteTime, &info->ChangeTime,
1654 &info->LastAccessTime, &info->CreationTime );
1655 if (S_ISDIR(st->st_mode)) info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1656 else info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1657 if (!(st->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1658 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1661 case FileStandardInformation:
1663 FILE_STANDARD_INFORMATION *info = ptr;
1665 if ((info->Directory = S_ISDIR(st->st_mode)))
1667 info->AllocationSize.QuadPart = 0;
1668 info->EndOfFile.QuadPart = 0;
1669 info->NumberOfLinks = 1;
1673 info->AllocationSize.QuadPart = (ULONGLONG)st->st_blocks * 512;
1674 info->EndOfFile.QuadPart = st->st_size;
1675 info->NumberOfLinks = st->st_nlink;
1679 case FileInternalInformation:
1681 FILE_INTERNAL_INFORMATION *info = ptr;
1682 info->IndexNumber.QuadPart = st->st_ino;
1685 case FileEndOfFileInformation:
1687 FILE_END_OF_FILE_INFORMATION *info = ptr;
1688 info->EndOfFile.QuadPart = S_ISDIR(st->st_mode) ? 0 : st->st_size;
1691 case FileAllInformation:
1693 FILE_ALL_INFORMATION *info = ptr;
1694 fill_stat_info( st, &info->BasicInformation, FileBasicInformation );
1695 fill_stat_info( st, &info->StandardInformation, FileStandardInformation );
1696 fill_stat_info( st, &info->InternalInformation, FileInternalInformation );
1699 /* all directory structures start with the FileDirectoryInformation layout */
1700 case FileBothDirectoryInformation:
1701 case FileFullDirectoryInformation:
1702 case FileDirectoryInformation:
1704 FILE_DIRECTORY_INFORMATION *info = ptr;
1706 get_file_times( st, &info->LastWriteTime, &info->ChangeTime,
1707 &info->LastAccessTime, &info->CreationTime );
1708 if (S_ISDIR(st->st_mode))
1710 info->AllocationSize.QuadPart = 0;
1711 info->EndOfFile.QuadPart = 0;
1712 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1716 info->AllocationSize.QuadPart = (ULONGLONG)st->st_blocks * 512;
1717 info->EndOfFile.QuadPart = st->st_size;
1718 info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1720 if (!(st->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1721 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1724 case FileIdFullDirectoryInformation:
1726 FILE_ID_FULL_DIRECTORY_INFORMATION *info = ptr;
1727 info->FileId.QuadPart = st->st_ino;
1728 fill_stat_info( st, info, FileDirectoryInformation );
1731 case FileIdBothDirectoryInformation:
1733 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = ptr;
1734 info->FileId.QuadPart = st->st_ino;
1735 fill_stat_info( st, info, FileDirectoryInformation );
1740 return STATUS_INVALID_INFO_CLASS;
1742 return STATUS_SUCCESS;
1745 NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name )
1747 data_size_t size = 1024;
1753 name = RtlAllocateHeap( GetProcessHeap(), 0, size + 1 );
1754 if (!name) return STATUS_NO_MEMORY;
1755 unix_name->MaximumLength = size + 1;
1757 SERVER_START_REQ( get_handle_unix_name )
1759 req->handle = wine_server_obj_handle( handle );
1760 wine_server_set_reply( req, name, size );
1761 ret = wine_server_call( req );
1762 size = reply->name_len;
1769 unix_name->Buffer = name;
1770 unix_name->Length = size;
1773 RtlFreeHeap( GetProcessHeap(), 0, name );
1774 if (ret != STATUS_BUFFER_OVERFLOW) break;
1779 static NTSTATUS fill_name_info( const ANSI_STRING *unix_name, FILE_NAME_INFORMATION *info, LONG *name_len )
1781 UNICODE_STRING nt_name;
1784 if (!(status = wine_unix_to_nt_file_name( unix_name, &nt_name )))
1786 const WCHAR *ptr = nt_name.Buffer;
1787 const WCHAR *end = ptr + (nt_name.Length / sizeof(WCHAR));
1789 /* Skip the volume mount point. */
1790 while (ptr != end && *ptr == '\\') ++ptr;
1791 while (ptr != end && *ptr != '\\') ++ptr;
1792 while (ptr != end && *ptr == '\\') ++ptr;
1793 while (ptr != end && *ptr != '\\') ++ptr;
1795 info->FileNameLength = (end - ptr) * sizeof(WCHAR);
1796 if (*name_len < info->FileNameLength) status = STATUS_BUFFER_OVERFLOW;
1797 else *name_len = info->FileNameLength;
1799 memcpy( info->FileName, ptr, *name_len );
1800 RtlFreeUnicodeString( &nt_name );
1806 /******************************************************************************
1807 * NtQueryInformationFile [NTDLL.@]
1808 * ZwQueryInformationFile [NTDLL.@]
1810 * Get information about an open file handle.
1813 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1814 * io [O] Receives information about the operation on return
1815 * ptr [O] Destination for file information
1816 * len [I] Size of FileInformation
1817 * class [I] Type of file information to get
1820 * Success: 0. IoStatusBlock and FileInformation are updated.
1821 * Failure: An NTSTATUS error code describing the error.
1823 NTSTATUS WINAPI NtQueryInformationFile( HANDLE hFile, PIO_STATUS_BLOCK io,
1824 PVOID ptr, LONG len, FILE_INFORMATION_CLASS class )
1826 static const size_t info_sizes[] =
1829 sizeof(FILE_DIRECTORY_INFORMATION), /* FileDirectoryInformation */
1830 sizeof(FILE_FULL_DIRECTORY_INFORMATION), /* FileFullDirectoryInformation */
1831 sizeof(FILE_BOTH_DIRECTORY_INFORMATION), /* FileBothDirectoryInformation */
1832 sizeof(FILE_BASIC_INFORMATION), /* FileBasicInformation */
1833 sizeof(FILE_STANDARD_INFORMATION), /* FileStandardInformation */
1834 sizeof(FILE_INTERNAL_INFORMATION), /* FileInternalInformation */
1835 sizeof(FILE_EA_INFORMATION), /* FileEaInformation */
1836 sizeof(FILE_ACCESS_INFORMATION), /* FileAccessInformation */
1837 sizeof(FILE_NAME_INFORMATION), /* FileNameInformation */
1838 sizeof(FILE_RENAME_INFORMATION)-sizeof(WCHAR), /* FileRenameInformation */
1839 0, /* FileLinkInformation */
1840 sizeof(FILE_NAMES_INFORMATION)-sizeof(WCHAR), /* FileNamesInformation */
1841 sizeof(FILE_DISPOSITION_INFORMATION), /* FileDispositionInformation */
1842 sizeof(FILE_POSITION_INFORMATION), /* FilePositionInformation */
1843 sizeof(FILE_FULL_EA_INFORMATION), /* FileFullEaInformation */
1844 sizeof(FILE_MODE_INFORMATION), /* FileModeInformation */
1845 sizeof(FILE_ALIGNMENT_INFORMATION), /* FileAlignmentInformation */
1846 sizeof(FILE_ALL_INFORMATION), /* FileAllInformation */
1847 sizeof(FILE_ALLOCATION_INFORMATION), /* FileAllocationInformation */
1848 sizeof(FILE_END_OF_FILE_INFORMATION), /* FileEndOfFileInformation */
1849 0, /* FileAlternateNameInformation */
1850 sizeof(FILE_STREAM_INFORMATION)-sizeof(WCHAR), /* FileStreamInformation */
1851 0, /* FilePipeInformation */
1852 sizeof(FILE_PIPE_LOCAL_INFORMATION), /* FilePipeLocalInformation */
1853 0, /* FilePipeRemoteInformation */
1854 sizeof(FILE_MAILSLOT_QUERY_INFORMATION), /* FileMailslotQueryInformation */
1855 0, /* FileMailslotSetInformation */
1856 0, /* FileCompressionInformation */
1857 0, /* FileObjectIdInformation */
1858 0, /* FileCompletionInformation */
1859 0, /* FileMoveClusterInformation */
1860 0, /* FileQuotaInformation */
1861 0, /* FileReparsePointInformation */
1862 0, /* FileNetworkOpenInformation */
1863 0, /* FileAttributeTagInformation */
1864 0, /* FileTrackingInformation */
1865 0, /* FileIdBothDirectoryInformation */
1866 0, /* FileIdFullDirectoryInformation */
1867 0, /* FileValidDataLengthInformation */
1868 0, /* FileShortNameInformation */
1872 0, /* FileSfioReserveInformation */
1873 0, /* FileSfioVolumeInformation */
1874 0, /* FileHardLinkInformation */
1876 0, /* FileNormalizedNameInformation */
1878 0, /* FileIdGlobalTxDirectoryInformation */
1882 0 /* FileStandardLinkInformation */
1886 int fd, needs_close = FALSE;
1888 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", hFile, io, ptr, len, class);
1890 io->Information = 0;
1892 if (class <= 0 || class >= FileMaximumInformation)
1893 return io->u.Status = STATUS_INVALID_INFO_CLASS;
1894 if (!info_sizes[class])
1896 FIXME("Unsupported class (%d)\n", class);
1897 return io->u.Status = STATUS_NOT_IMPLEMENTED;
1899 if (len < info_sizes[class])
1900 return io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
1902 if (class != FilePipeLocalInformation)
1904 if ((io->u.Status = server_get_unix_fd( hFile, 0, &fd, &needs_close, NULL, NULL )))
1905 return io->u.Status;
1910 case FileBasicInformation:
1911 if (fstat( fd, &st ) == -1)
1912 io->u.Status = FILE_GetNtStatus();
1913 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1914 io->u.Status = STATUS_INVALID_INFO_CLASS;
1916 fill_stat_info( &st, ptr, class );
1918 case FileStandardInformation:
1920 FILE_STANDARD_INFORMATION *info = ptr;
1922 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1925 fill_stat_info( &st, info, class );
1926 info->DeletePending = FALSE; /* FIXME */
1930 case FilePositionInformation:
1932 FILE_POSITION_INFORMATION *info = ptr;
1933 off_t res = lseek( fd, 0, SEEK_CUR );
1934 if (res == (off_t)-1) io->u.Status = FILE_GetNtStatus();
1935 else info->CurrentByteOffset.QuadPart = res;
1938 case FileInternalInformation:
1939 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1940 else fill_stat_info( &st, ptr, class );
1942 case FileEaInformation:
1944 FILE_EA_INFORMATION *info = ptr;
1948 case FileEndOfFileInformation:
1949 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1950 else fill_stat_info( &st, ptr, class );
1952 case FileAllInformation:
1954 FILE_ALL_INFORMATION *info = ptr;
1955 ANSI_STRING unix_name;
1957 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1958 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1959 io->u.Status = STATUS_INVALID_INFO_CLASS;
1960 else if (!(io->u.Status = server_get_unix_name( hFile, &unix_name )))
1962 LONG name_len = len - FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName);
1964 fill_stat_info( &st, info, FileAllInformation );
1965 info->StandardInformation.DeletePending = FALSE; /* FIXME */
1966 info->EaInformation.EaSize = 0;
1967 info->AccessInformation.AccessFlags = 0; /* FIXME */
1968 info->PositionInformation.CurrentByteOffset.QuadPart = lseek( fd, 0, SEEK_CUR );
1969 info->ModeInformation.Mode = 0; /* FIXME */
1970 info->AlignmentInformation.AlignmentRequirement = 1; /* FIXME */
1972 io->u.Status = fill_name_info( &unix_name, &info->NameInformation, &name_len );
1973 RtlFreeAnsiString( &unix_name );
1974 io->Information = FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName) + name_len;
1978 case FileMailslotQueryInformation:
1980 FILE_MAILSLOT_QUERY_INFORMATION *info = ptr;
1982 SERVER_START_REQ( set_mailslot_info )
1984 req->handle = wine_server_obj_handle( hFile );
1986 io->u.Status = wine_server_call( req );
1987 if( io->u.Status == STATUS_SUCCESS )
1989 info->MaximumMessageSize = reply->max_msgsize;
1990 info->MailslotQuota = 0;
1991 info->NextMessageSize = 0;
1992 info->MessagesAvailable = 0;
1993 info->ReadTimeout.QuadPart = reply->read_timeout;
2000 ULONG size = info->MaximumMessageSize ? info->MaximumMessageSize : 0x10000;
2001 if (size > 0x10000) size = 0x10000;
2002 if ((tmpbuf = RtlAllocateHeap( GetProcessHeap(), 0, size )))
2004 int fd, needs_close;
2005 if (!server_get_unix_fd( hFile, FILE_READ_DATA, &fd, &needs_close, NULL, NULL ))
2007 int res = recv( fd, tmpbuf, size, MSG_PEEK );
2008 info->MessagesAvailable = (res > 0);
2009 info->NextMessageSize = (res >= 0) ? res : MAILSLOT_NO_MESSAGE;
2010 if (needs_close) close( fd );
2012 RtlFreeHeap( GetProcessHeap(), 0, tmpbuf );
2017 case FilePipeLocalInformation:
2019 FILE_PIPE_LOCAL_INFORMATION* pli = ptr;
2021 SERVER_START_REQ( get_named_pipe_info )
2023 req->handle = wine_server_obj_handle( hFile );
2024 if (!(io->u.Status = wine_server_call( req )))
2026 pli->NamedPipeType = (reply->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) ?
2027 FILE_PIPE_TYPE_MESSAGE : FILE_PIPE_TYPE_BYTE;
2028 switch (reply->sharing)
2030 case FILE_SHARE_READ:
2031 pli->NamedPipeConfiguration = FILE_PIPE_OUTBOUND;
2033 case FILE_SHARE_WRITE:
2034 pli->NamedPipeConfiguration = FILE_PIPE_INBOUND;
2036 case FILE_SHARE_READ | FILE_SHARE_WRITE:
2037 pli->NamedPipeConfiguration = FILE_PIPE_FULL_DUPLEX;
2040 pli->MaximumInstances = reply->maxinstances;
2041 pli->CurrentInstances = reply->instances;
2042 pli->InboundQuota = reply->insize;
2043 pli->ReadDataAvailable = 0; /* FIXME */
2044 pli->OutboundQuota = reply->outsize;
2045 pli->WriteQuotaAvailable = 0; /* FIXME */
2046 pli->NamedPipeState = 0; /* FIXME */
2047 pli->NamedPipeEnd = (reply->flags & NAMED_PIPE_SERVER_END) ?
2048 FILE_PIPE_SERVER_END : FILE_PIPE_CLIENT_END;
2054 case FileNameInformation:
2056 FILE_NAME_INFORMATION *info = ptr;
2057 ANSI_STRING unix_name;
2059 if (!(io->u.Status = server_get_unix_name( hFile, &unix_name )))
2061 LONG name_len = len - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
2062 io->u.Status = fill_name_info( &unix_name, info, &name_len );
2063 RtlFreeAnsiString( &unix_name );
2064 io->Information = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + name_len;
2069 FIXME("Unsupported class (%d)\n", class);
2070 io->u.Status = STATUS_NOT_IMPLEMENTED;
2073 if (needs_close) close( fd );
2074 if (io->u.Status == STATUS_SUCCESS && !io->Information) io->Information = info_sizes[class];
2075 return io->u.Status;
2078 /******************************************************************************
2079 * NtSetInformationFile [NTDLL.@]
2080 * ZwSetInformationFile [NTDLL.@]
2082 * Set information about an open file handle.
2085 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2086 * io [O] Receives information about the operation on return
2087 * ptr [I] Source for file information
2088 * len [I] Size of FileInformation
2089 * class [I] Type of file information to set
2092 * Success: 0. io is updated.
2093 * Failure: An NTSTATUS error code describing the error.
2095 NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
2096 PVOID ptr, ULONG len, FILE_INFORMATION_CLASS class)
2098 int fd, needs_close;
2100 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", handle, io, ptr, len, class);
2102 io->u.Status = STATUS_SUCCESS;
2105 case FileBasicInformation:
2106 if (len >= sizeof(FILE_BASIC_INFORMATION))
2109 const FILE_BASIC_INFORMATION *info = ptr;
2111 if ((io->u.Status = server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
2112 return io->u.Status;
2114 if (info->LastAccessTime.QuadPart || info->LastWriteTime.QuadPart)
2115 io->u.Status = set_file_times( fd, &info->LastWriteTime, &info->LastAccessTime );
2117 if (io->u.Status == STATUS_SUCCESS && info->FileAttributes)
2119 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
2122 if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
2124 if (S_ISDIR( st.st_mode))
2125 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
2127 st.st_mode &= ~0222; /* clear write permission bits */
2131 /* add write permission only where we already have read permission */
2132 st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~FILE_umask);
2134 if (fchmod( fd, st.st_mode ) == -1) io->u.Status = FILE_GetNtStatus();
2138 if (needs_close) close( fd );
2140 else io->u.Status = STATUS_INVALID_PARAMETER_3;
2143 case FilePositionInformation:
2144 if (len >= sizeof(FILE_POSITION_INFORMATION))
2146 const FILE_POSITION_INFORMATION *info = ptr;
2148 if ((io->u.Status = server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
2149 return io->u.Status;
2151 if (lseek( fd, info->CurrentByteOffset.QuadPart, SEEK_SET ) == (off_t)-1)
2152 io->u.Status = FILE_GetNtStatus();
2154 if (needs_close) close( fd );
2156 else io->u.Status = STATUS_INVALID_PARAMETER_3;
2159 case FileEndOfFileInformation:
2160 if (len >= sizeof(FILE_END_OF_FILE_INFORMATION))
2163 const FILE_END_OF_FILE_INFORMATION *info = ptr;
2165 if ((io->u.Status = server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
2166 return io->u.Status;
2168 /* first try normal truncate */
2169 if (ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
2171 /* now check for the need to extend the file */
2172 if (fstat( fd, &st ) != -1 && (off_t)info->EndOfFile.QuadPart > st.st_size)
2174 static const char zero;
2176 /* extend the file one byte beyond the requested size and then truncate it */
2177 /* this should work around ftruncate implementations that can't extend files */
2178 if (pwrite( fd, &zero, 1, (off_t)info->EndOfFile.QuadPart ) != -1 &&
2179 ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
2181 io->u.Status = FILE_GetNtStatus();
2183 if (needs_close) close( fd );
2185 else io->u.Status = STATUS_INVALID_PARAMETER_3;
2188 case FileMailslotSetInformation:
2190 FILE_MAILSLOT_SET_INFORMATION *info = ptr;
2192 SERVER_START_REQ( set_mailslot_info )
2194 req->handle = wine_server_obj_handle( handle );
2195 req->flags = MAILSLOT_SET_READ_TIMEOUT;
2196 req->read_timeout = info->ReadTimeout.QuadPart;
2197 io->u.Status = wine_server_call( req );
2203 case FileCompletionInformation:
2204 if (len >= sizeof(FILE_COMPLETION_INFORMATION))
2206 FILE_COMPLETION_INFORMATION *info = ptr;
2208 SERVER_START_REQ( set_completion_info )
2210 req->handle = wine_server_obj_handle( handle );
2211 req->chandle = wine_server_obj_handle( info->CompletionPort );
2212 req->ckey = info->CompletionKey;
2213 io->u.Status = wine_server_call( req );
2217 io->u.Status = STATUS_INVALID_PARAMETER_3;
2220 case FileAllInformation:
2221 io->u.Status = STATUS_INVALID_INFO_CLASS;
2225 FIXME("Unsupported class (%d)\n", class);
2226 io->u.Status = STATUS_NOT_IMPLEMENTED;
2229 io->Information = 0;
2230 return io->u.Status;
2234 /******************************************************************************
2235 * NtQueryFullAttributesFile (NTDLL.@)
2237 NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
2238 FILE_NETWORK_OPEN_INFORMATION *info )
2240 ANSI_STRING unix_name;
2243 if (!(status = nt_to_unix_file_name_attr( attr, &unix_name, FILE_OPEN )))
2247 if (stat( unix_name.Buffer, &st ) == -1)
2248 status = FILE_GetNtStatus();
2249 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
2250 status = STATUS_INVALID_INFO_CLASS;
2253 FILE_BASIC_INFORMATION basic;
2254 FILE_STANDARD_INFORMATION std;
2256 fill_stat_info( &st, &basic, FileBasicInformation );
2257 fill_stat_info( &st, &std, FileStandardInformation );
2259 info->CreationTime = basic.CreationTime;
2260 info->LastAccessTime = basic.LastAccessTime;
2261 info->LastWriteTime = basic.LastWriteTime;
2262 info->ChangeTime = basic.ChangeTime;
2263 info->AllocationSize = std.AllocationSize;
2264 info->EndOfFile = std.EndOfFile;
2265 info->FileAttributes = basic.FileAttributes;
2266 if (DIR_is_hidden_file( attr->ObjectName ))
2267 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
2269 RtlFreeAnsiString( &unix_name );
2271 else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), status );
2276 /******************************************************************************
2277 * NtQueryAttributesFile (NTDLL.@)
2278 * ZwQueryAttributesFile (NTDLL.@)
2280 NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC_INFORMATION *info )
2282 ANSI_STRING unix_name;
2285 if (!(status = nt_to_unix_file_name_attr( attr, &unix_name, FILE_OPEN )))
2289 if (stat( unix_name.Buffer, &st ) == -1)
2290 status = FILE_GetNtStatus();
2291 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
2292 status = STATUS_INVALID_INFO_CLASS;
2295 status = fill_stat_info( &st, info, FileBasicInformation );
2296 if (DIR_is_hidden_file( attr->ObjectName ))
2297 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
2299 RtlFreeAnsiString( &unix_name );
2301 else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), status );
2306 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2307 /* helper for FILE_GetDeviceInfo to hide some platform differences in fstatfs */
2308 static inline void get_device_info_fstatfs( FILE_FS_DEVICE_INFORMATION *info, const char *fstypename,
2309 unsigned int flags )
2311 if (!strcmp("cd9660", fstypename) || !strcmp("udf", fstypename))
2313 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
2314 /* Don't assume read-only, let the mount options set it below */
2315 info->Characteristics |= FILE_REMOVABLE_MEDIA;
2317 else if (!strcmp("nfs", fstypename) || !strcmp("nwfs", fstypename) ||
2318 !strcmp("smbfs", fstypename) || !strcmp("afpfs", fstypename))
2320 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
2321 info->Characteristics |= FILE_REMOTE_DEVICE;
2323 else if (!strcmp("procfs", fstypename))
2324 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
2326 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2328 if (flags & MNT_RDONLY)
2329 info->Characteristics |= FILE_READ_ONLY_DEVICE;
2331 if (!(flags & MNT_LOCAL))
2333 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
2334 info->Characteristics |= FILE_REMOTE_DEVICE;
2339 static inline int is_device_placeholder( int fd )
2341 static const char wine_placeholder[] = "Wine device placeholder";
2342 char buffer[sizeof(wine_placeholder)-1];
2344 if (pread( fd, buffer, sizeof(wine_placeholder) - 1, 0 ) != sizeof(wine_placeholder) - 1)
2346 return !memcmp( buffer, wine_placeholder, sizeof(wine_placeholder) - 1 );
2349 /******************************************************************************
2352 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
2354 static NTSTATUS get_device_info( int fd, FILE_FS_DEVICE_INFORMATION *info )
2358 info->Characteristics = 0;
2359 if (fstat( fd, &st ) < 0) return FILE_GetNtStatus();
2360 if (S_ISCHR( st.st_mode ))
2362 info->DeviceType = FILE_DEVICE_UNKNOWN;
2364 switch(major(st.st_rdev))
2367 info->DeviceType = FILE_DEVICE_NULL;
2370 info->DeviceType = FILE_DEVICE_SERIAL_PORT;
2373 info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
2375 case SCSI_TAPE_MAJOR:
2376 info->DeviceType = FILE_DEVICE_TAPE;
2381 else if (S_ISBLK( st.st_mode ))
2383 info->DeviceType = FILE_DEVICE_DISK;
2385 else if (S_ISFIFO( st.st_mode ) || S_ISSOCK( st.st_mode ))
2387 info->DeviceType = FILE_DEVICE_NAMED_PIPE;
2389 else if (is_device_placeholder( fd ))
2391 info->DeviceType = FILE_DEVICE_DISK;
2393 else /* regular file or directory */
2395 #if defined(linux) && defined(HAVE_FSTATFS)
2398 /* check for floppy disk */
2399 if (major(st.st_dev) == FLOPPY_MAJOR)
2400 info->Characteristics |= FILE_REMOVABLE_MEDIA;
2402 if (fstatfs( fd, &stfs ) < 0) stfs.f_type = 0;
2403 switch (stfs.f_type)
2405 case 0x9660: /* iso9660 */
2406 case 0x9fa1: /* supermount */
2407 case 0x15013346: /* udf */
2408 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
2409 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
2411 case 0x6969: /* nfs */
2412 case 0x517B: /* smbfs */
2413 case 0x564c: /* ncpfs */
2414 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
2415 info->Characteristics |= FILE_REMOTE_DEVICE;
2417 case 0x01021994: /* tmpfs */
2418 case 0x28cd3d45: /* cramfs */
2419 case 0x1373: /* devfs */
2420 case 0x9fa0: /* procfs */
2421 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
2424 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2427 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2430 if (fstatfs( fd, &stfs ) < 0)
2431 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2433 get_device_info_fstatfs( info, stfs.f_fstypename, stfs.f_flags );
2434 #elif defined(__NetBSD__)
2435 struct statvfs stfs;
2437 if (fstatvfs( fd, &stfs) < 0)
2438 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2440 get_device_info_fstatfs( info, stfs.f_fstypename, stfs.f_flag );
2442 /* Use dkio to work out device types */
2444 # include <sys/dkio.h>
2445 # include <sys/vtoc.h>
2446 struct dk_cinfo dkinf;
2447 int retval = ioctl(fd, DKIOCINFO, &dkinf);
2449 WARN("Unable to get disk device type information - assuming a disk like device\n");
2450 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2452 switch (dkinf.dki_ctype)
2455 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
2456 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
2460 case DKC_INTEL82072:
2461 case DKC_INTEL82077:
2462 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2463 info->Characteristics |= FILE_REMOVABLE_MEDIA;
2466 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
2469 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2474 if (!warned++) FIXME( "device info not properly supported on this platform\n" );
2475 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
2477 info->Characteristics |= FILE_DEVICE_IS_MOUNTED;
2479 return STATUS_SUCCESS;
2483 /******************************************************************************
2484 * NtQueryVolumeInformationFile [NTDLL.@]
2485 * ZwQueryVolumeInformationFile [NTDLL.@]
2487 * Get volume information for an open file handle.
2490 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2491 * io [O] Receives information about the operation on return
2492 * buffer [O] Destination for volume information
2493 * length [I] Size of FsInformation
2494 * info_class [I] Type of volume information to set
2497 * Success: 0. io and buffer are updated.
2498 * Failure: An NTSTATUS error code describing the error.
2500 NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io,
2501 PVOID buffer, ULONG length,
2502 FS_INFORMATION_CLASS info_class )
2504 int fd, needs_close;
2508 if ((io->u.Status = server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )) != STATUS_SUCCESS)
2509 return io->u.Status;
2511 io->u.Status = STATUS_NOT_IMPLEMENTED;
2512 io->Information = 0;
2514 switch( info_class )
2516 case FileFsVolumeInformation:
2517 if (!once++) FIXME( "%p: volume info not supported\n", handle );
2519 case FileFsLabelInformation:
2520 FIXME( "%p: label info not supported\n", handle );
2522 case FileFsSizeInformation:
2523 if (length < sizeof(FILE_FS_SIZE_INFORMATION))
2524 io->u.Status = STATUS_BUFFER_TOO_SMALL;
2527 FILE_FS_SIZE_INFORMATION *info = buffer;
2529 if (fstat( fd, &st ) < 0)
2531 io->u.Status = FILE_GetNtStatus();
2534 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
2536 io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
2541 /* Linux's fstatvfs is buggy */
2542 #if !defined(linux) || !defined(HAVE_FSTATFS)
2543 struct statvfs stfs;
2545 if (fstatvfs( fd, &stfs ) < 0)
2547 io->u.Status = FILE_GetNtStatus();
2550 bsize = stfs.f_frsize;
2553 if (fstatfs( fd, &stfs ) < 0)
2555 io->u.Status = FILE_GetNtStatus();
2558 bsize = stfs.f_bsize;
2560 if (bsize == 2048) /* assume CD-ROM */
2562 info->BytesPerSector = 2048;
2563 info->SectorsPerAllocationUnit = 1;
2567 info->BytesPerSector = 512;
2568 info->SectorsPerAllocationUnit = 8;
2570 info->TotalAllocationUnits.QuadPart = bsize * stfs.f_blocks / (info->BytesPerSector * info->SectorsPerAllocationUnit);
2571 info->AvailableAllocationUnits.QuadPart = bsize * stfs.f_bavail / (info->BytesPerSector * info->SectorsPerAllocationUnit);
2572 io->Information = sizeof(*info);
2573 io->u.Status = STATUS_SUCCESS;
2577 case FileFsDeviceInformation:
2578 if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
2579 io->u.Status = STATUS_BUFFER_TOO_SMALL;
2582 FILE_FS_DEVICE_INFORMATION *info = buffer;
2584 if ((io->u.Status = get_device_info( fd, info )) == STATUS_SUCCESS)
2585 io->Information = sizeof(*info);
2588 case FileFsAttributeInformation:
2589 FIXME( "%p: attribute info not supported\n", handle );
2591 case FileFsControlInformation:
2592 FIXME( "%p: control info not supported\n", handle );
2594 case FileFsFullSizeInformation:
2595 FIXME( "%p: full size info not supported\n", handle );
2597 case FileFsObjectIdInformation:
2598 FIXME( "%p: object id info not supported\n", handle );
2600 case FileFsMaximumInformation:
2601 FIXME( "%p: maximum info not supported\n", handle );
2604 io->u.Status = STATUS_INVALID_PARAMETER;
2607 if (needs_close) close( fd );
2608 return io->u.Status;
2612 /******************************************************************
2613 * NtQueryEaFile (NTDLL.@)
2615 * Read extended attributes from NTFS files.
2618 * hFile [I] File handle, must be opened with FILE_READ_EA access
2619 * iosb [O] Receives information about the operation on return
2620 * buffer [O] Output buffer
2621 * length [I] Length of output buffer
2622 * single_entry [I] Only read and return one entry
2623 * ea_list [I] Optional list with names of EAs to return
2624 * ea_list_len [I] Length of ea_list in bytes
2625 * ea_index [I] Optional pointer to 1-based index of attribute to return
2626 * restart [I] restart EA scan
2629 * Success: 0. Atrributes read into buffer
2630 * Failure: An NTSTATUS error code describing the error.
2632 NTSTATUS WINAPI NtQueryEaFile( HANDLE hFile, PIO_STATUS_BLOCK iosb, PVOID buffer, ULONG length,
2633 BOOLEAN single_entry, PVOID ea_list, ULONG ea_list_len,
2634 PULONG ea_index, BOOLEAN restart )
2636 FIXME("(%p,%p,%p,%d,%d,%p,%d,%p,%d) stub\n",
2637 hFile, iosb, buffer, length, single_entry, ea_list,
2638 ea_list_len, ea_index, restart);
2639 return STATUS_ACCESS_DENIED;
2643 /******************************************************************
2644 * NtSetEaFile (NTDLL.@)
2646 * Update extended attributes for NTFS files.
2649 * hFile [I] File handle, must be opened with FILE_READ_EA access
2650 * iosb [O] Receives information about the operation on return
2651 * buffer [I] Buffer with EA information
2652 * length [I] Length of buffer
2655 * Success: 0. Attributes are updated
2656 * Failure: An NTSTATUS error code describing the error.
2658 NTSTATUS WINAPI NtSetEaFile( HANDLE hFile, PIO_STATUS_BLOCK iosb, PVOID buffer, ULONG length )
2660 FIXME("(%p,%p,%p,%d) stub\n", hFile, iosb, buffer, length);
2661 return STATUS_ACCESS_DENIED;
2665 /******************************************************************
2666 * NtFlushBuffersFile (NTDLL.@)
2668 * Flush any buffered data on an open file handle.
2671 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2672 * IoStatusBlock [O] Receives information about the operation on return
2675 * Success: 0. IoStatusBlock is updated.
2676 * Failure: An NTSTATUS error code describing the error.
2678 NTSTATUS WINAPI NtFlushBuffersFile( HANDLE hFile, IO_STATUS_BLOCK* IoStatusBlock )
2681 HANDLE hEvent = NULL;
2683 SERVER_START_REQ( flush_file )
2685 req->handle = wine_server_obj_handle( hFile );
2686 ret = wine_server_call( req );
2687 hEvent = wine_server_ptr_handle( reply->event );
2692 ret = NtWaitForSingleObject( hEvent, FALSE, NULL );
2698 /******************************************************************
2699 * NtLockFile (NTDLL.@)
2703 NTSTATUS WINAPI NtLockFile( HANDLE hFile, HANDLE lock_granted_event,
2704 PIO_APC_ROUTINE apc, void* apc_user,
2705 PIO_STATUS_BLOCK io_status, PLARGE_INTEGER offset,
2706 PLARGE_INTEGER count, ULONG* key, BOOLEAN dont_wait,
2712 static BOOLEAN warn = TRUE;
2714 if (apc || io_status || key)
2716 FIXME("Unimplemented yet parameter\n");
2717 return STATUS_NOT_IMPLEMENTED;
2720 if (apc_user && warn)
2722 FIXME("I/O completion on lock not implemented yet\n");
2728 SERVER_START_REQ( lock_file )
2730 req->handle = wine_server_obj_handle( hFile );
2731 req->offset = offset->QuadPart;
2732 req->count = count->QuadPart;
2733 req->shared = !exclusive;
2734 req->wait = !dont_wait;
2735 ret = wine_server_call( req );
2736 handle = wine_server_ptr_handle( reply->handle );
2737 async = reply->overlapped;
2740 if (ret != STATUS_PENDING)
2742 if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
2748 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
2749 if (handle) NtClose( handle );
2750 return STATUS_PENDING;
2754 NtWaitForSingleObject( handle, FALSE, NULL );
2761 /* Unix lock conflict, sleep a bit and retry */
2762 time.QuadPart = 100 * (ULONGLONG)10000;
2763 time.QuadPart = -time.QuadPart;
2764 NtDelayExecution( FALSE, &time );
2770 /******************************************************************
2771 * NtUnlockFile (NTDLL.@)
2775 NTSTATUS WINAPI NtUnlockFile( HANDLE hFile, PIO_STATUS_BLOCK io_status,
2776 PLARGE_INTEGER offset, PLARGE_INTEGER count,
2781 TRACE( "%p %x%08x %x%08x\n",
2782 hFile, offset->u.HighPart, offset->u.LowPart, count->u.HighPart, count->u.LowPart );
2784 if (io_status || key)
2786 FIXME("Unimplemented yet parameter\n");
2787 return STATUS_NOT_IMPLEMENTED;
2790 SERVER_START_REQ( unlock_file )
2792 req->handle = wine_server_obj_handle( hFile );
2793 req->offset = offset->QuadPart;
2794 req->count = count->QuadPart;
2795 status = wine_server_call( req );
2801 /******************************************************************
2802 * NtCreateNamedPipeFile (NTDLL.@)
2806 NTSTATUS WINAPI NtCreateNamedPipeFile( PHANDLE handle, ULONG access,
2807 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK iosb,
2808 ULONG sharing, ULONG dispo, ULONG options,
2809 ULONG pipe_type, ULONG read_mode,
2810 ULONG completion_mode, ULONG max_inst,
2811 ULONG inbound_quota, ULONG outbound_quota,
2812 PLARGE_INTEGER timeout)
2816 TRACE("(%p %x %s %p %x %d %x %d %d %d %d %d %d %p)\n",
2817 handle, access, debugstr_w(attr->ObjectName->Buffer), iosb, sharing, dispo,
2818 options, pipe_type, read_mode, completion_mode, max_inst, inbound_quota,
2819 outbound_quota, timeout);
2821 /* assume we only get relative timeout */
2822 if (timeout->QuadPart > 0)
2823 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout->QuadPart));
2825 SERVER_START_REQ( create_named_pipe )
2827 req->access = access;
2828 req->attributes = attr->Attributes;
2829 req->rootdir = wine_server_obj_handle( attr->RootDirectory );
2830 req->options = options;
2831 req->sharing = sharing;
2833 (pipe_type ? NAMED_PIPE_MESSAGE_STREAM_WRITE : 0) |
2834 (read_mode ? NAMED_PIPE_MESSAGE_STREAM_READ : 0) |
2835 (completion_mode ? NAMED_PIPE_NONBLOCKING_MODE : 0);
2836 req->maxinstances = max_inst;
2837 req->outsize = outbound_quota;
2838 req->insize = inbound_quota;
2839 req->timeout = timeout->QuadPart;
2840 wine_server_add_data( req, attr->ObjectName->Buffer,
2841 attr->ObjectName->Length );
2842 status = wine_server_call( req );
2843 if (!status) *handle = wine_server_ptr_handle( reply->handle );
2849 /******************************************************************
2850 * NtDeleteFile (NTDLL.@)
2854 NTSTATUS WINAPI NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes )
2860 TRACE("%p\n", ObjectAttributes);
2861 status = NtCreateFile( &hFile, GENERIC_READ | GENERIC_WRITE | DELETE,
2862 ObjectAttributes, &io, NULL, 0,
2863 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
2864 FILE_OPEN, FILE_DELETE_ON_CLOSE, NULL, 0 );
2865 if (status == STATUS_SUCCESS) status = NtClose(hFile);
2869 /******************************************************************
2870 * NtCancelIoFileEx (NTDLL.@)
2874 NTSTATUS WINAPI NtCancelIoFileEx( HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status )
2876 LARGE_INTEGER timeout;
2878 TRACE("%p %p %p\n", hFile, iosb, io_status );
2880 SERVER_START_REQ( cancel_async )
2882 req->handle = wine_server_obj_handle( hFile );
2883 req->iosb = wine_server_client_ptr( iosb );
2884 req->only_thread = FALSE;
2885 io_status->u.Status = wine_server_call( req );
2888 if (io_status->u.Status)
2889 return io_status->u.Status;
2891 /* Let some APC be run, so that we can run the remaining APCs on hFile
2892 * either the cancelation of the pending one, but also the execution
2893 * of the queued APC, but not yet run. This is needed to ensure proper
2894 * clean-up of allocated data.
2896 timeout.QuadPart = 0;
2897 NtDelayExecution( TRUE, &timeout );
2898 return io_status->u.Status;
2901 /******************************************************************
2902 * NtCancelIoFile (NTDLL.@)
2906 NTSTATUS WINAPI NtCancelIoFile( HANDLE hFile, PIO_STATUS_BLOCK io_status )
2908 LARGE_INTEGER timeout;
2910 TRACE("%p %p\n", hFile, io_status );
2912 SERVER_START_REQ( cancel_async )
2914 req->handle = wine_server_obj_handle( hFile );
2916 req->only_thread = TRUE;
2917 io_status->u.Status = wine_server_call( req );
2920 if (io_status->u.Status)
2921 return io_status->u.Status;
2923 /* Let some APC be run, so that we can run the remaining APCs on hFile
2924 * either the cancelation of the pending one, but also the execution
2925 * of the queued APC, but not yet run. This is needed to ensure proper
2926 * clean-up of allocated data.
2928 timeout.QuadPart = 0;
2929 NtDelayExecution( TRUE, &timeout );
2930 return io_status->u.Status;
2933 /******************************************************************************
2934 * NtCreateMailslotFile [NTDLL.@]
2935 * ZwCreateMailslotFile [NTDLL.@]
2938 * pHandle [O] pointer to receive the handle created
2939 * DesiredAccess [I] access mode (read, write, etc)
2940 * ObjectAttributes [I] fully qualified NT path of the mailslot
2941 * IoStatusBlock [O] receives completion status and other info
2944 * MaxMessageSize [I]
2950 NTSTATUS WINAPI NtCreateMailslotFile(PHANDLE pHandle, ULONG DesiredAccess,
2951 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK IoStatusBlock,
2952 ULONG CreateOptions, ULONG MailslotQuota, ULONG MaxMessageSize,
2953 PLARGE_INTEGER TimeOut)
2955 LARGE_INTEGER timeout;
2958 TRACE("%p %08x %p %p %08x %08x %08x %p\n",
2959 pHandle, DesiredAccess, attr, IoStatusBlock,
2960 CreateOptions, MailslotQuota, MaxMessageSize, TimeOut);
2962 if (!pHandle) return STATUS_ACCESS_VIOLATION;
2963 if (!attr) return STATUS_INVALID_PARAMETER;
2964 if (!attr->ObjectName) return STATUS_OBJECT_PATH_SYNTAX_BAD;
2967 * For a NULL TimeOut pointer set the default timeout value
2970 timeout.QuadPart = -1;
2972 timeout.QuadPart = TimeOut->QuadPart;
2974 SERVER_START_REQ( create_mailslot )
2976 req->access = DesiredAccess;
2977 req->attributes = attr->Attributes;
2978 req->rootdir = wine_server_obj_handle( attr->RootDirectory );
2979 req->max_msgsize = MaxMessageSize;
2980 req->read_timeout = timeout.QuadPart;
2981 wine_server_add_data( req, attr->ObjectName->Buffer,
2982 attr->ObjectName->Length );
2983 ret = wine_server_call( req );
2984 if( ret == STATUS_SUCCESS )
2985 *pHandle = wine_server_ptr_handle( reply->handle );