/* INCLUDES *****************************************************************/
#include <k32.h>
+#include <wine/debug.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(kernel32file);
-#define NDEBUG
//#define USING_PROPER_NPFS_WAIT_SEMANTICS
-#include "../include/debug.h"
/* FUNCTIONS ****************************************************************/
lpSecurityAttributes);
}
+
/*
* @implemented
*/
HANDLE
-STDCALL
+WINAPI
CreateNamedPipeW(LPCWSTR lpName,
DWORD dwOpenMode,
DWORD dwPipeMode,
}
/* Convert to NT syntax */
- if (nMaxInstances == PIPE_UNLIMITED_INSTANCES) nMaxInstances = -1;
+ if (nMaxInstances == PIPE_UNLIMITED_INSTANCES)
+ nMaxInstances = -1;
/* Convert the name */
Result = RtlDosPathNameToNtPathName_U(lpName,
if (!Result)
{
/* Conversion failed */
- SetLastError(ERROR_PATH_NOT_FOUND);
- return(INVALID_HANDLE_VALUE);
+ SetLastError(ERROR_PATH_NOT_FOUND);
+ return INVALID_HANDLE_VALUE;
}
- DPRINT("Pipe name: %wZ\n", &NamedPipeName);
- DPRINT("Pipe name: %S\n", NamedPipeName.Buffer);
+ TRACE("Pipe name: %wZ\n", &NamedPipeName);
+ TRACE("Pipe name: %S\n", NamedPipeName.Buffer);
/* Always case insensitive, check if we got extra attributes */
Attributes = OBJ_CASE_INSENSITIVE;
SecurityDescriptor = lpSecurityAttributes->lpSecurityDescriptor;
/* And check if this is pipe's handle will beinheritable */
- if(lpSecurityAttributes->bInheritHandle) Attributes |= OBJ_INHERIT;
+ if (lpSecurityAttributes->bInheritHandle)
+ Attributes |= OBJ_INHERIT;
}
/* Now we can initialize the object attributes */
{
CreateOptions |= FILE_WRITE_THROUGH;
}
+
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED))
{
CreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
}
- /* Handle all open modes */
+ /* Handle all open modes */
if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
{
ShareAccess |= FILE_SHARE_READ;
DesiredAccess |= GENERIC_WRITE;
}
+
if (dwOpenMode & PIPE_ACCESS_INBOUND)
{
ShareAccess |= FILE_SHARE_WRITE;
if (!NT_SUCCESS(Status))
{
/* Failed to create it */
- DPRINT1("NtCreateNamedPipe failed (Status %x)!\n", Status);
+ WARN("NtCreateNamedPipe failed (Status %x)!\n", Status);
SetLastErrorByStatus (Status);
return INVALID_HANDLE_VALUE;
}
return PipeHandle;
}
+
/*
* @implemented
*/
UNICODE_STRING NameU;
/* Convert the name to Unicode */
- Basep8BitStringToLiveUnicodeString(&NameU, lpNamedPipeName);
+ Basep8BitStringToHeapUnicodeString(&NameU, lpNamedPipeName);
/* Call the Unicode API */
r = WaitNamedPipeW(NameU.Buffer, nTimeOut);
return r;
}
+
/*
* When NPFS will work properly, use this code instead. It is compatible with
* Microsoft's NPFS.SYS. The main difference is that:
* - This code actually respects the timeout instead of ignoring it!
* - This code validates and creates the proper names for both UNC and local pipes
- * - On NT, you open the *root* pipe directory (either \DosDevices\Pipe or
- * \DosDevices\Unc\Server\Pipe) and then send the pipe to wait on in the
+ * - On NT, you open the *root* pipe directory (either \DosDevices\Pipe or
+ * \DosDevices\Unc\Server\Pipe) and then send the pipe to wait on in the
* FILE_PIPE_WAIT_FOR_BUFFER structure.
*/
#ifdef USING_PROPER_NPFS_WAIT_SEMANTICS
PFILE_PIPE_WAIT_FOR_BUFFER WaitPipeInfo;
/* Start by making a unicode string of the name */
- DPRINT("Sent path: %S\n", lpNamedPipeName);
+ TRACE("Sent path: %S\n", lpNamedPipeName);
RtlCreateUnicodeString(&NamedPipeName, lpNamedPipeName);
NameLength = NamedPipeName.Length / sizeof(WCHAR);
/* Find the path type of the name we were given */
NewName = NamedPipeName;
Type = RtlDetermineDosPathNameType_U(lpNamedPipeName);
-
+
/* Check if this was a device path, ie : "\\.\pipe\name" */
if (Type == RtlPathTypeLocalDevice)
{
NewName.Length -= 9 * sizeof(WCHAR);
/* Initialize the Dos Devices name */
- DPRINT("NewName: %wZ\n", &NewName);
+ TRACE("NewName: %wZ\n", &NewName);
RtlInitUnicodeString(&DevicePath, L"\\DosDevices\\pipe\\");
}
else if (Type == RtlPathTypeRootLocalDevice)
else
{
/* The name is invalid */
- DPRINT1("Invalid name!\n");
- SetLastErrorByStatus(STATUS_OBJECT_PATH_SYNTAX_BAD);
- return FALSE;
+ WARN("Invalid name!\n");
+ SetLastErrorByStatus(STATUS_OBJECT_PATH_SYNTAX_BAD);
+ return FALSE;
}
/* FIXME: Open \DosDevices\Unc\Server\Pipe\Name */
}
else
{
- DPRINT1("Invalid path type\n");
+ WARN("Invalid path type\n");
SetLastErrorByStatus(STATUS_OBJECT_PATH_SYNTAX_BAD);
return FALSE;
}
}
/* Initialize the object attributes */
- DPRINT("Opening: %wZ\n", &DevicePath);
+ TRACE("Opening: %wZ\n", &DevicePath);
InitializeObjectAttributes(&ObjectAttributes,
&DevicePath,
OBJ_CASE_INSENSITIVE,
if (!NT_SUCCESS(Status))
{
/* Fail; couldn't open */
- DPRINT1("Status: %lx\n", Status);
+ WARN("Status: %lx\n", Status);
SetLastErrorByStatus(Status);
RtlFreeUnicodeString(&NamedPipeName);
RtlFreeHeap(RtlGetProcessHeap(), 0, WaitPipeInfo);
- return(FALSE);
+ return FALSE;
}
/* Check what timeout we got */
}
/* In both cases, we do have a timeout */
- WaitPipeInfo->TimeoutSpecified = FALSE;
+ WaitPipeInfo->TimeoutSpecified = TRUE;
}
/* Set the length and copy the name */
if (!NT_SUCCESS(Status))
{
/* Failure to wait on the pipe */
- DPRINT1("Status: %lx\n", Status);
+ WARN("Status: %lx\n", Status);
SetLastErrorByStatus (Status);
return FALSE;
}
/*
* @implemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
WaitNamedPipeW(LPCWSTR lpNamedPipeName,
- DWORD nTimeOut)
+ DWORD nTimeOut)
{
- UNICODE_STRING NamedPipeName;
- BOOL r;
- NTSTATUS Status;
- OBJECT_ATTRIBUTES ObjectAttributes;
- FILE_PIPE_WAIT_FOR_BUFFER WaitPipe;
- HANDLE FileHandle;
- IO_STATUS_BLOCK Iosb;
-
- r = RtlDosPathNameToNtPathName_U(lpNamedPipeName,
- &NamedPipeName,
- NULL,
- NULL);
- if (!r)
- {
- return(FALSE);
- }
+ UNICODE_STRING NamedPipeName;
+ NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ FILE_PIPE_WAIT_FOR_BUFFER WaitPipe;
+ HANDLE FileHandle;
+ IO_STATUS_BLOCK Iosb;
- InitializeObjectAttributes(&ObjectAttributes,
- &NamedPipeName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
- Status = NtOpenFile(&FileHandle,
- FILE_READ_ATTRIBUTES | SYNCHRONIZE,
- &ObjectAttributes,
- &Iosb,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- FILE_SYNCHRONOUS_IO_NONALERT);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return(FALSE);
- }
+ if (RtlDosPathNameToNtPathName_U(lpNamedPipeName,
+ &NamedPipeName,
+ NULL,
+ NULL) == FALSE)
+ {
+ return FALSE;
+ }
- WaitPipe.Timeout.QuadPart = nTimeOut * -10000LL;
-
- Status = NtFsControlFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- FSCTL_PIPE_WAIT,
- &WaitPipe,
- sizeof(WaitPipe),
- NULL,
- 0);
- NtClose(FileHandle);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return(FALSE);
- }
+ InitializeObjectAttributes(&ObjectAttributes,
+ &NamedPipeName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+ Status = NtOpenFile(&FileHandle,
+ FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+ &ObjectAttributes,
+ &Iosb,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ RtlFreeUnicodeString(&NamedPipeName);
+ return FALSE;
+ }
+
+ /* Check what timeout we got */
+ if (nTimeOut == NMPWAIT_USE_DEFAULT_WAIT)
+ {
+ /* Don't use a timeout */
+ WaitPipe.TimeoutSpecified = FALSE;
+ }
+ else
+ {
+ /* Check if we should wait forever */
+ if (nTimeOut == NMPWAIT_WAIT_FOREVER)
+ {
+ /* Set the max */
+ WaitPipe.Timeout.LowPart = 0;
+ WaitPipe.Timeout.HighPart = 0x80000000;
+ }
+ else
+ {
+ /* Convert to NT format */
+ WaitPipe.Timeout.QuadPart = UInt32x32To64(-10000, nTimeOut);
+ }
+
+ /* In both cases, we do have a timeout */
+ WaitPipe.TimeoutSpecified = TRUE;
+ }
+
+ Status = NtFsControlFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &Iosb,
+ FSCTL_PIPE_WAIT,
+ &WaitPipe,
+ sizeof(WaitPipe),
+ NULL,
+ 0);
+ NtClose(FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ RtlFreeUnicodeString(&NamedPipeName);
+ return FALSE;
+ }
- return(TRUE);
+ RtlFreeUnicodeString(&NamedPipeName);
+ return TRUE;
}
#endif
+
/*
* @implemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
ConnectNamedPipe(IN HANDLE hNamedPipe,
IN LPOVERLAPPED lpOverlapped)
{
- NTSTATUS Status;
+ NTSTATUS Status;
- if (lpOverlapped != NULL)
- {
+ if (lpOverlapped != NULL)
+ {
PVOID ApcContext;
lpOverlapped->Internal = STATUS_PENDING;
/* return FALSE in case of failure and pending operations! */
if (!NT_SUCCESS(Status) || Status == STATUS_PENDING)
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
- }
- else
- {
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+ }
+ else
+ {
IO_STATUS_BLOCK Iosb;
Status = NtFsControlFile(hNamedPipe,
/* wait in case operation is pending */
if (Status == STATUS_PENDING)
- {
+ {
Status = NtWaitForSingleObject(hNamedPipe,
FALSE,
NULL);
if (NT_SUCCESS(Status))
- {
- Status = Iosb.Status;
- }
- }
+ {
+ Status = Iosb.Status;
+ }
+ }
if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
- }
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+ }
- return TRUE;
+ return TRUE;
}
+
/*
* @implemented
*/
BOOL
-STDCALL
+WINAPI
SetNamedPipeHandleState(HANDLE hNamedPipe,
LPDWORD lpMode,
LPDWORD lpMaxCollectionCount,
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
- return(FALSE);
+ return FALSE;
}
}
&RemoteSettings,
sizeof(FILE_PIPE_REMOTE_INFORMATION),
FilePipeRemoteInformation);
-
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
- return(FALSE);
+ return FALSE;
}
}
if (lpCollectDataTimeout)
{
/* Convert it to Quad */
- RemoteSettings.CollectDataTime.QuadPart = -(LONGLONG)
- UInt32x32To64(10000,
- *lpCollectDataTimeout);
+ RemoteSettings.CollectDataTime.QuadPart =
+ -(LONGLONG)UInt32x32To64(10000, *lpCollectDataTimeout);
}
/* Tell the driver to change them */
&RemoteSettings,
sizeof(FILE_PIPE_REMOTE_INFORMATION),
FilePipeRemoteInformation);
-
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
- return(FALSE);
+ return FALSE;
}
}
- /* All done */
return TRUE;
}
+
/*
* @implemented
*/
nTimeOut);
}
+
/*
* @implemented
*/
NULL);
/* Success, break out */
- if (hPipe != INVALID_HANDLE_VALUE) break;
+ if (hPipe != INVALID_HANDLE_VALUE)
+ break;
/* Already tried twice, give up */
- if (bRetry == FALSE) return FALSE;
+ if (bRetry == FALSE)
+ return FALSE;
/* Wait on it */
WaitNamedPipeW(lpNamedPipeName, nTimeOut);
nOutBufferSize,
lpBytesRead,
NULL);
-
- /* Close the handle and return */
+
+ /* Close the handle */
CloseHandle(hPipe);
+
return bError;
}
+
/*
* @implemented
*/
-BOOL
+BOOL
WINAPI
DisconnectNamedPipe(HANDLE hNamedPipe)
{
{
/* Wait on NPFS to finish and get updated status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
- if (NT_SUCCESS(Status)) Status = Iosb.Status;
+ if (NT_SUCCESS(Status))
+ Status = Iosb.Status;
}
/* Check for error */
/* Fail */
SetLastErrorByStatus(Status);
return FALSE;
- }
-
+ }
+
return TRUE;
}
+
/*
* @unimplemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
GetNamedPipeHandleStateW(HANDLE hNamedPipe,
- LPDWORD lpState,
- LPDWORD lpCurInstances,
- LPDWORD lpMaxCollectionCount,
- LPDWORD lpCollectDataTimeout,
- LPWSTR lpUserName,
- DWORD nMaxUserNameSize)
+ LPDWORD lpState,
+ LPDWORD lpCurInstances,
+ LPDWORD lpMaxCollectionCount,
+ LPDWORD lpCollectDataTimeout,
+ LPWSTR lpUserName,
+ DWORD nMaxUserNameSize)
{
- IO_STATUS_BLOCK StatusBlock;
- NTSTATUS Status;
-
- if (lpState != NULL)
- {
- FILE_PIPE_INFORMATION PipeInfo;
+ IO_STATUS_BLOCK StatusBlock;
+ NTSTATUS Status;
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &PipeInfo,
- sizeof(FILE_PIPE_INFORMATION),
- FilePipeInformation);
- if (!NT_SUCCESS(Status))
+ if (lpState != NULL)
{
- SetLastErrorByStatus(Status);
- return FALSE;
- }
-
- *lpState = ((PipeInfo.CompletionMode != FILE_PIPE_QUEUE_OPERATION) ? PIPE_NOWAIT : PIPE_WAIT);
- *lpState |= ((PipeInfo.ReadMode != FILE_PIPE_BYTE_STREAM_MODE) ? PIPE_READMODE_MESSAGE : PIPE_READMODE_BYTE);
- }
+ FILE_PIPE_INFORMATION PipeInfo;
- if(lpCurInstances != NULL)
- {
- FILE_PIPE_LOCAL_INFORMATION LocalInfo;
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &PipeInfo,
+ sizeof(FILE_PIPE_INFORMATION),
+ FilePipeInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &LocalInfo,
- sizeof(FILE_PIPE_LOCAL_INFORMATION),
- FilePipeLocalInformation);
- if(!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
+ *lpState = ((PipeInfo.CompletionMode != FILE_PIPE_QUEUE_OPERATION) ? PIPE_NOWAIT : PIPE_WAIT);
+ *lpState |= ((PipeInfo.ReadMode != FILE_PIPE_BYTE_STREAM_MODE) ? PIPE_READMODE_MESSAGE : PIPE_READMODE_BYTE);
}
- *lpCurInstances = min(LocalInfo.CurrentInstances, PIPE_UNLIMITED_INSTANCES);
- }
+ if(lpCurInstances != NULL)
+ {
+ FILE_PIPE_LOCAL_INFORMATION LocalInfo;
- if(lpMaxCollectionCount != NULL || lpCollectDataTimeout != NULL)
- {
- FILE_PIPE_REMOTE_INFORMATION RemoteInfo;
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &LocalInfo,
+ sizeof(FILE_PIPE_LOCAL_INFORMATION),
+ FilePipeLocalInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &RemoteInfo,
- sizeof(FILE_PIPE_REMOTE_INFORMATION),
- FilePipeRemoteInformation);
- if(!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
+ *lpCurInstances = min(LocalInfo.CurrentInstances, PIPE_UNLIMITED_INSTANCES);
}
- if(lpMaxCollectionCount != NULL)
+ if (lpMaxCollectionCount != NULL || lpCollectDataTimeout != NULL)
{
- *lpMaxCollectionCount = RemoteInfo.MaximumCollectionCount;
+ FILE_PIPE_REMOTE_INFORMATION RemoteInfo;
+
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &RemoteInfo,
+ sizeof(FILE_PIPE_REMOTE_INFORMATION),
+ FilePipeRemoteInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ if (lpMaxCollectionCount != NULL)
+ {
+ *lpMaxCollectionCount = RemoteInfo.MaximumCollectionCount;
+ }
+
+ if(lpCollectDataTimeout != NULL)
+ {
+ /* FIXME */
+ *lpCollectDataTimeout = 0;
+ }
}
- if(lpCollectDataTimeout != NULL)
+ if (lpUserName != NULL)
{
- /* FIXME */
- *lpCollectDataTimeout = 0;
+ /* FIXME - open the thread token, call ImpersonateNamedPipeClient() and
+ retreive the user name with GetUserName(), revert the impersonation
+ and finally restore the thread token */
}
- }
- if(lpUserName != NULL)
- {
- /* FIXME - open the thread token, call ImpersonateNamedPipeClient() and
- retreive the user name with GetUserName(), revert the impersonation
- and finally restore the thread token */
- }
-
- return TRUE;
+ return TRUE;
}
/*
* @implemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
GetNamedPipeHandleStateA(HANDLE hNamedPipe,
- LPDWORD lpState,
- LPDWORD lpCurInstances,
- LPDWORD lpMaxCollectionCount,
- LPDWORD lpCollectDataTimeout,
- LPSTR lpUserName,
- DWORD nMaxUserNameSize)
+ LPDWORD lpState,
+ LPDWORD lpCurInstances,
+ LPDWORD lpMaxCollectionCount,
+ LPDWORD lpCollectDataTimeout,
+ LPSTR lpUserName,
+ DWORD nMaxUserNameSize)
{
- UNICODE_STRING UserNameW = {0};
- ANSI_STRING UserNameA;
- BOOL Ret;
-
- if(lpUserName != NULL)
- {
- UserNameW.MaximumLength = (USHORT)nMaxUserNameSize * sizeof(WCHAR);
- UserNameW.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, UserNameW.MaximumLength);
- if (UserNameW.Buffer == NULL)
+ UNICODE_STRING UserNameW = { 0, 0, NULL };
+ ANSI_STRING UserNameA;
+ BOOL Ret;
+
+ if(lpUserName != NULL)
{
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
- }
+ UserNameW.MaximumLength = (USHORT)nMaxUserNameSize * sizeof(WCHAR);
+ UserNameW.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, UserNameW.MaximumLength);
+ if (UserNameW.Buffer == NULL)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
- UserNameA.Buffer = lpUserName;
- UserNameA.Length = 0;
- UserNameA.MaximumLength = (USHORT)nMaxUserNameSize;
- }
-
- Ret = GetNamedPipeHandleStateW(hNamedPipe,
- lpState,
- lpCurInstances,
- lpMaxCollectionCount,
- lpCollectDataTimeout,
- UserNameW.Buffer,
- nMaxUserNameSize);
-
- if(Ret && lpUserName != NULL)
- {
- NTSTATUS Status;
+ UserNameA.Buffer = lpUserName;
+ UserNameA.Length = 0;
+ UserNameA.MaximumLength = (USHORT)nMaxUserNameSize;
+ }
- RtlInitUnicodeString(&UserNameW, UserNameW.Buffer);
- Status = RtlUnicodeStringToAnsiString(&UserNameA, &UserNameW, FALSE);
- if(!NT_SUCCESS(Status))
+ Ret = GetNamedPipeHandleStateW(hNamedPipe,
+ lpState,
+ lpCurInstances,
+ lpMaxCollectionCount,
+ lpCollectDataTimeout,
+ UserNameW.Buffer,
+ nMaxUserNameSize);
+ if (Ret && lpUserName != NULL)
{
- SetLastErrorByStatus(Status);
- Ret = FALSE;
+ NTSTATUS Status;
+
+ RtlInitUnicodeString(&UserNameW, UserNameW.Buffer);
+ Status = RtlUnicodeStringToAnsiString(&UserNameA, &UserNameW, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ Ret = FALSE;
+ }
}
- }
- if(UserNameW.Buffer != NULL)
- {
- RtlFreeHeap(RtlGetProcessHeap(), 0, UserNameW.Buffer);
- }
+ if (UserNameW.Buffer != NULL)
+ {
+ RtlFreeHeap(RtlGetProcessHeap(), 0, UserNameW.Buffer);
+ }
- return Ret;
+ return Ret;
}
/*
* @implemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
GetNamedPipeInfo(HANDLE hNamedPipe,
- LPDWORD lpFlags,
- LPDWORD lpOutBufferSize,
- LPDWORD lpInBufferSize,
- LPDWORD lpMaxInstances)
+ LPDWORD lpFlags,
+ LPDWORD lpOutBufferSize,
+ LPDWORD lpInBufferSize,
+ LPDWORD lpMaxInstances)
{
- FILE_PIPE_LOCAL_INFORMATION PipeLocalInformation;
- IO_STATUS_BLOCK StatusBlock;
- NTSTATUS Status;
-
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &PipeLocalInformation,
- sizeof(FILE_PIPE_LOCAL_INFORMATION),
- FilePipeLocalInformation);
- if (!NT_SUCCESS(Status))
+ FILE_PIPE_LOCAL_INFORMATION PipeLocalInformation;
+ IO_STATUS_BLOCK StatusBlock;
+ NTSTATUS Status;
+
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &PipeLocalInformation,
+ sizeof(FILE_PIPE_LOCAL_INFORMATION),
+ FilePipeLocalInformation);
+ if (!NT_SUCCESS(Status))
{
- SetLastErrorByStatus(Status);
- return(FALSE);
+ SetLastErrorByStatus(Status);
+ return FALSE;
}
- if (lpFlags != NULL)
+ if (lpFlags != NULL)
{
- *lpFlags = (PipeLocalInformation.NamedPipeEnd == FILE_PIPE_SERVER_END) ? PIPE_SERVER_END : PIPE_CLIENT_END;
- *lpFlags |= (PipeLocalInformation.NamedPipeType == 1) ? PIPE_TYPE_MESSAGE : PIPE_TYPE_BYTE;
+ *lpFlags = (PipeLocalInformation.NamedPipeEnd == FILE_PIPE_SERVER_END) ? PIPE_SERVER_END : PIPE_CLIENT_END;
+ *lpFlags |= (PipeLocalInformation.NamedPipeType == 1) ? PIPE_TYPE_MESSAGE : PIPE_TYPE_BYTE;
}
- if (lpOutBufferSize != NULL)
- *lpOutBufferSize = PipeLocalInformation.OutboundQuota;
+ if (lpOutBufferSize != NULL)
+ *lpOutBufferSize = PipeLocalInformation.OutboundQuota;
- if (lpInBufferSize != NULL)
- *lpInBufferSize = PipeLocalInformation.InboundQuota;
+ if (lpInBufferSize != NULL)
+ *lpInBufferSize = PipeLocalInformation.InboundQuota;
- if (lpMaxInstances != NULL)
+ if (lpMaxInstances != NULL)
{
- if (PipeLocalInformation.MaximumInstances >= 255)
- *lpMaxInstances = PIPE_UNLIMITED_INSTANCES;
- else
- *lpMaxInstances = PipeLocalInformation.MaximumInstances;
+ if (PipeLocalInformation.MaximumInstances >= 255)
+ *lpMaxInstances = PIPE_UNLIMITED_INSTANCES;
+ else
+ *lpMaxInstances = PipeLocalInformation.MaximumInstances;
}
- return(TRUE);
+ return TRUE;
}
+
/*
* @implemented
*/
PFILE_PIPE_PEEK_BUFFER Buffer;
IO_STATUS_BLOCK Iosb;
ULONG BufferSize;
+ ULONG BytesRead;
NTSTATUS Status;
/* Calculate the buffer space that we'll need and allocate it */
- BufferSize = nBufferSize + FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]);
+ BufferSize = nBufferSize + sizeof(FILE_PIPE_PEEK_BUFFER);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize);
if (Buffer == NULL)
{
{
/* Wait for npfs to be done, and update the status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
- if (NT_SUCCESS(Status)) Status = Iosb.Status;
+ if (NT_SUCCESS(Status))
+ Status = Iosb.Status;
}
/* Overflow is success for us */
- if (Status == STATUS_BUFFER_OVERFLOW) Status = STATUS_SUCCESS;
+ if (Status == STATUS_BUFFER_OVERFLOW)
+ Status = STATUS_SUCCESS;
/* If we failed */
if (!NT_SUCCESS(Status))
}
/* Check if caller requested bytes available */
- if (lpTotalBytesAvail) *lpTotalBytesAvail = Buffer->ReadDataAvailable;
+ if (lpTotalBytesAvail)
+ *lpTotalBytesAvail = Buffer->ReadDataAvailable;
+
+ /* Calculate the bytes returned, minus our structure overhead */
+ BytesRead = (ULONG)(Iosb.Information -
+ FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
/* Check if caller requested bytes read */
if (lpBytesRead)
{
- /* Calculate the bytes returned, minus our structure overhead */
- *lpBytesRead = (ULONG)(Iosb.Information -
- FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
+ /* Return the bytes read */
+ *lpBytesRead = BytesRead;
}
/* Check if caller requested bytes left */
if (lpBytesLeftThisMessage)
{
/* Calculate total minus what we returned and our structure overhead */
- *lpBytesLeftThisMessage = Buffer->MessageLength -
- (ULONG)(Iosb.Information -
- FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
+ *lpBytesLeftThisMessage = Buffer->MessageLength - BytesRead;
}
/* Check if the caller wanted to see the actual data */
/* Give him what he wants */
RtlCopyMemory(lpBuffer,
Buffer->Data,
- Iosb.Information -
- FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
+ BytesRead);
}
- /* Free the buffer and return success */
+ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
+
return TRUE;
}
+
/*
* @implemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
TransactNamedPipe(IN HANDLE hNamedPipe,
IN LPVOID lpInBuffer,
IN DWORD nInBufferSize,
OUT LPDWORD lpBytesRead OPTIONAL,
IN LPOVERLAPPED lpOverlapped OPTIONAL)
{
- NTSTATUS Status;
+ NTSTATUS Status;
- if (lpBytesRead != NULL)
- {
+ if (lpBytesRead != NULL)
+ {
*lpBytesRead = 0;
- }
+ }
- if (lpOverlapped != NULL)
- {
+ if (lpOverlapped != NULL)
+ {
PVOID ApcContext;
ApcContext = (((ULONG_PTR)lpOverlapped->hEvent & 0x1) ? NULL : lpOverlapped);
nInBufferSize,
lpOutBuffer,
nOutBufferSize);
-
- /* return FALSE in case of failure and pending operations! */
if (!NT_SUCCESS(Status) || Status == STATUS_PENDING)
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
if (lpBytesRead != NULL)
- {
- *lpBytesRead = lpOverlapped->InternalHigh;
- }
- }
- else
- {
+ {
+ *lpBytesRead = lpOverlapped->InternalHigh;
+ }
+ }
+ else
+ {
#if 0 /* We don't implement FSCTL_PIPE_TRANSCEIVE yet */
IO_STATUS_BLOCK Iosb;
nInBufferSize,
lpOutBuffer,
nOutBufferSize);
-
- /* wait in case operation is pending */
if (Status == STATUS_PENDING)
- {
- Status = NtWaitForSingleObject(hNamedPipe,
- FALSE,
- NULL);
- if (NT_SUCCESS(Status))
- {
- Status = Iosb.Status;
- }
- }
+ {
+ Status = NtWaitForSingleObject(hNamedPipe,
+ FALSE,
+ NULL);
+ if (NT_SUCCESS(Status))
+ Status = Iosb.Status;
+ }
if (NT_SUCCESS(Status))
- {
- /* lpNumberOfBytesRead must not be NULL here, in fact Win doesn't
- check that case either and crashes (only after the operation
- completed) */
- *lpBytesRead = Iosb.Information;
- }
+ {
+ /* lpNumberOfBytesRead must not be NULL here, in fact Win doesn't
+ check that case either and crashes (only after the operation
+ completed) */
+ *lpBytesRead = Iosb.Information;
+ }
else
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
#else /* Workaround while FSCTL_PIPE_TRANSCEIVE not available */
DWORD nActualBytes;
while (0 != nInBufferSize &&
WriteFile(hNamedPipe, lpInBuffer, nInBufferSize, &nActualBytes,
NULL))
- {
+ {
lpInBuffer = (LPVOID)((char *) lpInBuffer + nActualBytes);
nInBufferSize -= nActualBytes;
- }
+ }
+
if (0 != nInBufferSize)
- {
+ {
/* Must have dropped out of the while 'cause WriteFile failed */
return FALSE;
- }
- if (! ReadFile(hNamedPipe, lpOutBuffer, nOutBufferSize, &nActualBytes,
- NULL))
- {
+ }
+
+ if (!ReadFile(hNamedPipe, lpOutBuffer, nOutBufferSize, &nActualBytes,
+ NULL))
+ {
return FALSE;
- }
+ }
+
if (NULL != lpBytesRead)
- {
+ {
*lpBytesRead = nActualBytes;
- }
+ }
#endif
- }
+ }
- return TRUE;
+ return TRUE;
}
/* EOF */