ntdll: Always use server ioctl for FSCTL_PIPE_PEEK.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2017-10-05 14:30:36 +02:00 committed by Alexandre Julliard
parent d520f30b4d
commit 1e87417e7f
2 changed files with 8 additions and 63 deletions

View File

@ -1699,69 +1699,6 @@ NTSTATUS WINAPI NtFsControlFile(HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc
if (!status) status = DIR_unmount_device( handle );
return status;
case FSCTL_PIPE_PEEK:
{
FILE_PIPE_PEEK_BUFFER *buffer = out_buffer;
int avail = 0, fd, needs_close;
if (out_size < FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data ))
{
status = STATUS_INFO_LENGTH_MISMATCH;
break;
}
if ((status = server_get_unix_fd( handle, FILE_READ_DATA, &fd, &needs_close, NULL, NULL )))
{
if (status == STATUS_BAD_DEVICE_TYPE)
return server_ioctl_file( handle, event, apc, apc_context, io, code,
in_buffer, in_size, out_buffer, out_size );
break;
}
#ifdef FIONREAD
if (ioctl( fd, FIONREAD, &avail ) != 0)
{
TRACE("FIONREAD failed reason: %s\n",strerror(errno));
if (needs_close) close( fd );
status = FILE_GetNtStatus();
break;
}
#endif
if (!avail) /* check for closed pipe */
{
struct pollfd pollfd;
int ret;
pollfd.fd = fd;
pollfd.events = POLLIN;
pollfd.revents = 0;
ret = poll( &pollfd, 1, 0 );
if (ret == -1 || (ret == 1 && (pollfd.revents & (POLLHUP|POLLERR))))
{
if (needs_close) close( fd );
status = STATUS_PIPE_BROKEN;
break;
}
}
buffer->NamedPipeState = 0; /* FIXME */
buffer->ReadDataAvailable = avail;
buffer->NumberOfMessages = 0; /* FIXME */
buffer->MessageLength = 0; /* FIXME */
io->Information = FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data );
status = STATUS_SUCCESS;
if (avail)
{
ULONG data_size = out_size - FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data );
if (data_size)
{
int res = recv( fd, buffer->Data, data_size, MSG_PEEK );
if (res >= 0) io->Information += res;
}
}
if (needs_close) close( fd );
}
break;
case FSCTL_PIPE_DISCONNECT:
status = server_ioctl_file( handle, event, apc, apc_context, io, code,
in_buffer, in_size, out_buffer, out_size );

View File

@ -4179,6 +4179,7 @@ static void test_read_write(void)
static void test_ioctl(void)
{
HANDLE event = CreateEventA(NULL, TRUE, FALSE, NULL);
FILE_PIPE_PEEK_BUFFER peek_buf;
IO_STATUS_BLOCK iosb;
HANDLE file;
NTSTATUS status;
@ -4195,6 +4196,13 @@ static void test_ioctl(void)
status = pNtFsControlFile(file, (HANDLE)0xdeadbeef, NULL, NULL, &iosb, 0xdeadbeef, 0, 0, 0, 0);
ok(status == STATUS_INVALID_HANDLE, "NtFsControlFile returned %x\n", status);
memset(&iosb, 0x55, sizeof(iosb));
status = NtFsControlFile(file, NULL, NULL, NULL, &iosb, FSCTL_PIPE_PEEK, NULL, 0,
&peek_buf, sizeof(peek_buf));
todo_wine
ok(status == STATUS_INVALID_DEVICE_REQUEST, "NtFsControlFile failed: %x\n", status);
ok(iosb.Status == 0x55555555, "iosb.Status = %x\n", iosb.Status);
CloseHandle(event);
CloseHandle(file);
}