Module: wine Branch: master Commit: 2d6366fc299cdfe0005b6c34f0cb7a1d95257341 URL: http://source.winehq.org/git/wine.git/?a=commit;h=2d6366fc299cdfe0005b6c34f0...
Author: Alexandre Julliard julliard@winehq.org Date: Fri Mar 14 20:30:12 2008 +0100
ntdll: Implemented NtWriteFileGather.
---
dlls/ntdll/file.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ dlls/ntdll/ntdll.spec | 4 +- include/winternl.h | 2 +- 3 files changed, 92 insertions(+), 3 deletions(-)
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index 3b67832..ce94917 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -1037,6 +1037,95 @@ err: }
+/****************************************************************************** + * NtWriteFileGather [NTDLL.@] + * ZwWriteFileGather [NTDLL.@] + */ +NTSTATUS WINAPI NtWriteFileGather( HANDLE file, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user, + PIO_STATUS_BLOCK io_status, FILE_SEGMENT_ELEMENT *segments, + ULONG length, PLARGE_INTEGER offset, PULONG key ) +{ + size_t page_size = getpagesize(); + int result, unix_handle, needs_close; + unsigned int options; + NTSTATUS status; + ULONG pos = 0, total = 0; + enum server_fd_type type; + ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user; + + TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n", + file, event, apc, apc_user, io_status, segments, length, offset, key); + + if (length % page_size) return STATUS_INVALID_PARAMETER; + if (!io_status) return STATUS_ACCESS_VIOLATION; + + status = server_get_unix_fd( file, FILE_WRITE_DATA, &unix_handle, + &needs_close, &type, &options ); + if (status) return status; + + if ((type != FD_TYPE_FILE) || + (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) || + !(options & FILE_NO_INTERMEDIATE_BUFFERING)) + { + status = STATUS_INVALID_PARAMETER; + goto error; + } + + while (length) + { + if (offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */) + result = pwrite( unix_handle, (char *)segments->Buffer + pos, + page_size - pos, offset->QuadPart + total ); + else + result = write( unix_handle, (char *)segments->Buffer + pos, page_size - pos ); + + if (result == -1) + { + if (errno == EINTR) continue; + if (errno == EFAULT) + { + status = STATUS_INVALID_USER_BUFFER; + goto error; + } + status = FILE_GetNtStatus(); + break; + } + if (!result) + { + status = STATUS_DISK_FULL; + break; + } + total += result; + length -= result; + if ((pos += result) == page_size) + { + pos = 0; + segments++; + } + } + + if (cvalue) NTDLL_AddCompletion( file, cvalue, status, total ); + + error: + if (needs_close) close( unix_handle ); + if (status == STATUS_SUCCESS) + { + io_status->u.Status = status; + io_status->Information = total; + TRACE("= SUCCESS (%u)\n", total); + if (event) NtSetEvent( event, NULL ); + if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc, + (ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 ); + } + else + { + TRACE("= 0x%08x\n", status); + if (status != STATUS_PENDING && event) NtResetEvent( event, NULL ); + } + return status; +} + + struct async_ioctl { HANDLE handle; /* handle to the device */ diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index ebb65f4..0c9bfd4 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -375,7 +375,7 @@ @ stub NtWaitHighEventPair @ stub NtWaitLowEventPair @ stdcall NtWriteFile(long long ptr ptr ptr ptr long ptr ptr) -@ stub NtWriteFileGather +@ stdcall NtWriteFileGather(long long ptr ptr ptr ptr long ptr ptr) @ stub NtWriteRequestData @ stdcall NtWriteVirtualMemory(long ptr ptr long ptr) @ stdcall NtYieldExecution() @@ -1218,7 +1218,7 @@ @ stub ZwWaitHighEventPair @ stub ZwWaitLowEventPair @ stdcall ZwWriteFile(long long ptr ptr ptr ptr long ptr ptr) NtWriteFile -# @ stub ZwWriteFileGather +@ stdcall ZwWriteFileGather(long long ptr ptr ptr ptr long ptr ptr) NtWriteFileGather @ stub ZwWriteRequestData @ stdcall ZwWriteVirtualMemory(long ptr ptr long ptr) NtWriteVirtualMemory @ stdcall ZwYieldExecution() NtYieldExecution diff --git a/include/winternl.h b/include/winternl.h index 5b54295..eafbbed 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2057,7 +2057,7 @@ NTSYSAPI NTSTATUS WINAPI NtWaitForMultipleObjects(ULONG,const HANDLE*,BOOLEAN,B NTSYSAPI NTSTATUS WINAPI NtWaitHighEventPair(HANDLE); NTSYSAPI NTSTATUS WINAPI NtWaitLowEventPair(HANDLE); NTSYSAPI NTSTATUS WINAPI NtWriteFile(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,const void*,ULONG,PLARGE_INTEGER,PULONG); -NTSYSAPI NTSTATUS WINAPI NtWriteFileGather(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,FILE_SEGMENT_ELEMENT,ULONG,PLARGE_INTEGER,PULONG); +NTSYSAPI NTSTATUS WINAPI NtWriteFileGather(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,FILE_SEGMENT_ELEMENT*,ULONG,PLARGE_INTEGER,PULONG); NTSYSAPI NTSTATUS WINAPI NtWriteRequestData(HANDLE,PLPC_MESSAGE,ULONG,PVOID,ULONG,PULONG); NTSYSAPI NTSTATUS WINAPI NtWriteVirtualMemory(HANDLE,void*,const void*,SIZE_T,SIZE_T*); NTSYSAPI NTSTATUS WINAPI NtYieldExecution(void);