2 * Server-side pipe management
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2001 Mike McCormack
6 * Copyright 2016 Jacek Caban for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
33 #define WIN32_NO_STATUS
49 struct list entry
; /* entry in message queue */
50 data_size_t read_pos
; /* already read bytes */
51 struct iosb
*iosb
; /* message iosb */
52 struct async
*async
; /* async of pending write */
57 struct object obj
; /* object header */
58 struct fd
*fd
; /* pipe file descriptor */
59 unsigned int flags
; /* pipe flags */
60 unsigned int state
; /* pipe state */
61 struct named_pipe
*pipe
;
62 struct pipe_end
*connection
; /* the other end of the pipe */
63 process_id_t client_pid
; /* process that created the client */
64 process_id_t server_pid
; /* process that created the server */
65 data_size_t buffer_size
;/* size of buffered data that doesn't block caller */
66 struct list message_queue
;
67 struct async_queue read_q
; /* read queue */
68 struct async_queue write_q
; /* write queue */
73 struct pipe_end pipe_end
; /* common header for both pipe ends */
74 struct list entry
; /* entry in named pipe servers list */
75 unsigned int options
; /* pipe options */
76 struct async_queue listen_q
; /* listen queue */
81 struct object obj
; /* object header */
84 unsigned int maxinstances
;
87 unsigned int instances
;
89 struct list servers
; /* list of servers using this pipe */
90 struct async_queue waiters
; /* list of clients waiting to connect */
93 struct named_pipe_device
95 struct object obj
; /* object header */
96 struct namespace *pipes
; /* named pipe namespace */
99 struct named_pipe_device_file
101 struct object obj
; /* object header */
102 struct fd
*fd
; /* pseudo-fd for ioctls */
103 struct named_pipe_device
*device
; /* named pipe device */
106 static void named_pipe_dump( struct object
*obj
, int verbose
);
107 static unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
);
108 static int named_pipe_link_name( struct object
*obj
, struct object_name
*name
, struct object
*parent
);
109 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
110 unsigned int sharing
, unsigned int options
);
111 static void named_pipe_destroy( struct object
*obj
);
113 static const struct object_ops named_pipe_ops
=
115 sizeof(struct named_pipe
), /* size */
116 named_pipe_dump
, /* dump */
117 no_get_type
, /* get_type */
118 no_add_queue
, /* add_queue */
119 NULL
, /* remove_queue */
121 NULL
, /* satisfied */
122 no_signal
, /* signal */
123 no_get_fd
, /* get_fd */
124 named_pipe_map_access
, /* map_access */
125 default_get_sd
, /* get_sd */
126 default_set_sd
, /* set_sd */
127 no_lookup_name
, /* lookup_name */
128 named_pipe_link_name
, /* link_name */
129 default_unlink_name
, /* unlink_name */
130 named_pipe_open_file
, /* open_file */
131 no_close_handle
, /* close_handle */
132 named_pipe_destroy
/* destroy */
135 /* common server and client pipe end functions */
136 static void pipe_end_destroy( struct object
*obj
);
137 static struct object_type
*pipe_end_get_type( struct object
*obj
);
138 static enum server_fd_type
pipe_end_get_fd_type( struct fd
*fd
);
139 static struct fd
*pipe_end_get_fd( struct object
*obj
);
140 static struct security_descriptor
*pipe_end_get_sd( struct object
*obj
);
141 static int pipe_end_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
142 unsigned int set_info
);
143 static int pipe_end_read( struct fd
*fd
, struct async
*async
, file_pos_t pos
);
144 static int pipe_end_write( struct fd
*fd
, struct async
*async_data
, file_pos_t pos
);
145 static int pipe_end_flush( struct fd
*fd
, struct async
*async
);
146 static void pipe_end_get_volume_info( struct fd
*fd
, unsigned int info_class
);
147 static void pipe_end_reselect_async( struct fd
*fd
, struct async_queue
*queue
);
148 static void pipe_end_get_file_info( struct fd
*fd
, obj_handle_t handle
, unsigned int info_class
);
150 /* server end functions */
151 static void pipe_server_dump( struct object
*obj
, int verbose
);
152 static void pipe_server_destroy( struct object
*obj
);
153 static int pipe_server_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
155 static const struct object_ops pipe_server_ops
=
157 sizeof(struct pipe_server
), /* size */
158 pipe_server_dump
, /* dump */
159 pipe_end_get_type
, /* get_type */
160 add_queue
, /* add_queue */
161 remove_queue
, /* remove_queue */
162 default_fd_signaled
, /* signaled */
163 no_satisfied
, /* satisfied */
164 no_signal
, /* signal */
165 pipe_end_get_fd
, /* get_fd */
166 default_fd_map_access
, /* map_access */
167 pipe_end_get_sd
, /* get_sd */
168 pipe_end_set_sd
, /* set_sd */
169 no_lookup_name
, /* lookup_name */
170 no_link_name
, /* link_name */
171 NULL
, /* unlink_name */
172 no_open_file
, /* open_file */
173 fd_close_handle
, /* close_handle */
174 pipe_server_destroy
/* destroy */
177 static const struct fd_ops pipe_server_fd_ops
=
179 default_fd_get_poll_events
, /* get_poll_events */
180 default_poll_event
, /* poll_event */
181 pipe_end_get_fd_type
, /* get_fd_type */
182 pipe_end_read
, /* read */
183 pipe_end_write
, /* write */
184 pipe_end_flush
, /* flush */
185 pipe_end_get_file_info
, /* get_file_info */
186 pipe_end_get_volume_info
, /* get_volume_info */
187 pipe_server_ioctl
, /* ioctl */
188 no_fd_queue_async
, /* queue_async */
189 pipe_end_reselect_async
/* reselect_async */
192 /* client end functions */
193 static void pipe_client_dump( struct object
*obj
, int verbose
);
194 static int pipe_client_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
196 static const struct object_ops pipe_client_ops
=
198 sizeof(struct pipe_end
), /* size */
199 pipe_client_dump
, /* dump */
200 pipe_end_get_type
, /* get_type */
201 add_queue
, /* add_queue */
202 remove_queue
, /* remove_queue */
203 default_fd_signaled
, /* signaled */
204 no_satisfied
, /* satisfied */
205 no_signal
, /* signal */
206 pipe_end_get_fd
, /* get_fd */
207 default_fd_map_access
, /* map_access */
208 pipe_end_get_sd
, /* get_sd */
209 pipe_end_set_sd
, /* set_sd */
210 no_lookup_name
, /* lookup_name */
211 no_link_name
, /* link_name */
212 NULL
, /* unlink_name */
213 no_open_file
, /* open_file */
214 fd_close_handle
, /* close_handle */
215 pipe_end_destroy
/* destroy */
218 static const struct fd_ops pipe_client_fd_ops
=
220 default_fd_get_poll_events
, /* get_poll_events */
221 default_poll_event
, /* poll_event */
222 pipe_end_get_fd_type
, /* get_fd_type */
223 pipe_end_read
, /* read */
224 pipe_end_write
, /* write */
225 pipe_end_flush
, /* flush */
226 pipe_end_get_file_info
, /* get_file_info */
227 pipe_end_get_volume_info
, /* get_volume_info */
228 pipe_client_ioctl
, /* ioctl */
229 no_fd_queue_async
, /* queue_async */
230 pipe_end_reselect_async
/* reselect_async */
233 static void named_pipe_device_dump( struct object
*obj
, int verbose
);
234 static struct object_type
*named_pipe_device_get_type( struct object
*obj
);
235 static struct object
*named_pipe_device_lookup_name( struct object
*obj
,
236 struct unicode_str
*name
, unsigned int attr
);
237 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
238 unsigned int sharing
, unsigned int options
);
239 static void named_pipe_device_destroy( struct object
*obj
);
241 static const struct object_ops named_pipe_device_ops
=
243 sizeof(struct named_pipe_device
), /* size */
244 named_pipe_device_dump
, /* dump */
245 named_pipe_device_get_type
, /* get_type */
246 no_add_queue
, /* add_queue */
247 NULL
, /* remove_queue */
249 no_satisfied
, /* satisfied */
250 no_signal
, /* signal */
251 no_get_fd
, /* get_fd */
252 no_map_access
, /* map_access */
253 default_get_sd
, /* get_sd */
254 default_set_sd
, /* set_sd */
255 named_pipe_device_lookup_name
, /* lookup_name */
256 directory_link_name
, /* link_name */
257 default_unlink_name
, /* unlink_name */
258 named_pipe_device_open_file
, /* open_file */
259 no_close_handle
, /* close_handle */
260 named_pipe_device_destroy
/* destroy */
263 static void named_pipe_device_file_dump( struct object
*obj
, int verbose
);
264 static struct fd
*named_pipe_device_file_get_fd( struct object
*obj
);
265 static int named_pipe_device_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
266 static enum server_fd_type
named_pipe_device_file_get_fd_type( struct fd
*fd
);
267 static void named_pipe_device_file_destroy( struct object
*obj
);
269 static const struct object_ops named_pipe_device_file_ops
=
271 sizeof(struct named_pipe_device_file
), /* size */
272 named_pipe_device_file_dump
, /* dump */
273 no_get_type
, /* get_type */
274 add_queue
, /* add_queue */
275 remove_queue
, /* remove_queue */
276 default_fd_signaled
, /* signaled */
277 no_satisfied
, /* satisfied */
278 no_signal
, /* signal */
279 named_pipe_device_file_get_fd
, /* get_fd */
280 default_fd_map_access
, /* map_access */
281 default_get_sd
, /* get_sd */
282 default_set_sd
, /* set_sd */
283 no_lookup_name
, /* lookup_name */
284 no_link_name
, /* link_name */
285 NULL
, /* unlink_name */
286 no_open_file
, /* open_file */
287 fd_close_handle
, /* close_handle */
288 named_pipe_device_file_destroy
/* destroy */
291 static const struct fd_ops named_pipe_device_fd_ops
=
293 default_fd_get_poll_events
, /* get_poll_events */
294 default_poll_event
, /* poll_event */
295 named_pipe_device_file_get_fd_type
, /* get_fd_type */
296 no_fd_read
, /* read */
297 no_fd_write
, /* write */
298 no_fd_flush
, /* flush */
299 default_fd_get_file_info
, /* get_file_info */
300 no_fd_get_volume_info
, /* get_volume_info */
301 named_pipe_device_ioctl
, /* ioctl */
302 default_fd_queue_async
, /* queue_async */
303 default_fd_reselect_async
/* reselect_async */
306 static void named_pipe_dump( struct object
*obj
, int verbose
)
308 fputs( "Named pipe\n", stderr
);
311 static unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
)
313 if (access
& GENERIC_READ
) access
|= STANDARD_RIGHTS_READ
;
314 if (access
& GENERIC_WRITE
) access
|= STANDARD_RIGHTS_WRITE
| FILE_CREATE_PIPE_INSTANCE
;
315 if (access
& GENERIC_EXECUTE
) access
|= STANDARD_RIGHTS_EXECUTE
;
316 if (access
& GENERIC_ALL
) access
|= STANDARD_RIGHTS_ALL
;
317 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
320 static void pipe_server_dump( struct object
*obj
, int verbose
)
322 struct pipe_server
*server
= (struct pipe_server
*) obj
;
323 assert( obj
->ops
== &pipe_server_ops
);
324 fprintf( stderr
, "Named pipe server pipe=%p state=%d\n", server
->pipe_end
.pipe
,
325 server
->pipe_end
.state
);
328 static void pipe_client_dump( struct object
*obj
, int verbose
)
330 struct pipe_end
*client
= (struct pipe_end
*) obj
;
331 assert( obj
->ops
== &pipe_client_ops
);
332 fprintf( stderr
, "Named pipe client server=%p\n", client
->connection
);
335 static void named_pipe_destroy( struct object
*obj
)
337 struct named_pipe
*pipe
= (struct named_pipe
*) obj
;
339 assert( list_empty( &pipe
->servers
) );
340 assert( !pipe
->instances
);
341 free_async_queue( &pipe
->waiters
);
344 static struct object_type
*pipe_end_get_type( struct object
*obj
)
346 static const WCHAR name
[] = {'F','i','l','e'};
347 static const struct unicode_str str
= { name
, sizeof(name
) };
348 return get_object_type( &str
);
351 static struct fd
*pipe_end_get_fd( struct object
*obj
)
353 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
354 return (struct fd
*) grab_object( pipe_end
->fd
);
357 static struct pipe_message
*queue_message( struct pipe_end
*pipe_end
, struct iosb
*iosb
)
359 struct pipe_message
*message
;
361 if (!(message
= mem_alloc( sizeof(*message
) ))) return NULL
;
362 message
->iosb
= (struct iosb
*)grab_object( iosb
);
363 message
->async
= NULL
;
364 message
->read_pos
= 0;
365 list_add_tail( &pipe_end
->message_queue
, &message
->entry
);
369 static void wake_message( struct pipe_message
*message
)
371 struct async
*async
= message
->async
;
373 message
->async
= NULL
;
376 message
->iosb
->status
= STATUS_SUCCESS
;
377 message
->iosb
->result
= message
->iosb
->in_size
;
378 async_terminate( async
, message
->iosb
->result
? STATUS_ALERTED
: STATUS_SUCCESS
);
379 release_object( async
);
382 static void free_message( struct pipe_message
*message
)
384 list_remove( &message
->entry
);
385 if (message
->iosb
) release_object( message
->iosb
);
389 static void pipe_end_disconnect( struct pipe_end
*pipe_end
, unsigned int status
)
391 struct pipe_end
*connection
= pipe_end
->connection
;
392 struct pipe_message
*message
, *next
;
395 pipe_end
->connection
= NULL
;
397 pipe_end
->state
= status
== STATUS_PIPE_DISCONNECTED
398 ? FILE_PIPE_DISCONNECTED_STATE
: FILE_PIPE_CLOSING_STATE
;
399 fd_async_wake_up( pipe_end
->fd
, ASYNC_TYPE_WAIT
, status
);
400 async_wake_up( &pipe_end
->read_q
, status
);
401 LIST_FOR_EACH_ENTRY_SAFE( message
, next
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
403 async
= message
->async
;
404 if (async
|| status
== STATUS_PIPE_DISCONNECTED
) free_message( message
);
405 if (!async
) continue;
406 async_terminate( async
, status
);
407 release_object( async
);
409 if (status
== STATUS_PIPE_DISCONNECTED
) set_fd_signaled( pipe_end
->fd
, 0 );
413 connection
->connection
= NULL
;
414 pipe_end_disconnect( connection
, status
);
418 static void pipe_end_destroy( struct object
*obj
)
420 struct pipe_end
*pipe_end
= (struct pipe_end
*)obj
;
421 struct pipe_message
*message
;
423 pipe_end_disconnect( pipe_end
, STATUS_PIPE_BROKEN
);
425 while (!list_empty( &pipe_end
->message_queue
))
427 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
428 assert( !message
->async
);
429 free_message( message
);
432 free_async_queue( &pipe_end
->read_q
);
433 free_async_queue( &pipe_end
->write_q
);
434 if (pipe_end
->fd
) release_object( pipe_end
->fd
);
435 if (pipe_end
->pipe
) release_object( pipe_end
->pipe
);
438 static void pipe_server_destroy( struct object
*obj
)
440 struct pipe_server
*server
= (struct pipe_server
*)obj
;
441 struct named_pipe
*pipe
= server
->pipe_end
.pipe
;
443 assert( obj
->ops
== &pipe_server_ops
);
445 assert( pipe
->instances
);
446 if (!--pipe
->instances
) unlink_named_object( &pipe
->obj
);
447 list_remove( &server
->entry
);
449 free_async_queue( &server
->listen_q
);
450 pipe_end_destroy( obj
);
453 static void named_pipe_device_dump( struct object
*obj
, int verbose
)
455 fputs( "Named pipe device\n", stderr
);
458 static struct object_type
*named_pipe_device_get_type( struct object
*obj
)
460 static const WCHAR name
[] = {'D','e','v','i','c','e'};
461 static const struct unicode_str str
= { name
, sizeof(name
) };
462 return get_object_type( &str
);
465 static struct object
*named_pipe_device_lookup_name( struct object
*obj
, struct unicode_str
*name
,
468 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
469 struct object
*found
;
471 assert( obj
->ops
== &named_pipe_device_ops
);
472 assert( device
->pipes
);
474 if (!name
) return NULL
; /* open the device itself */
476 if ((found
= find_object( device
->pipes
, name
, attr
| OBJ_CASE_INSENSITIVE
)))
482 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
483 unsigned int sharing
, unsigned int options
)
485 struct named_pipe_device_file
*file
;
487 if (!(file
= alloc_object( &named_pipe_device_file_ops
))) return NULL
;
488 file
->device
= (struct named_pipe_device
*)grab_object( obj
);
489 if (!(file
->fd
= alloc_pseudo_fd( &named_pipe_device_fd_ops
, obj
, options
)))
491 release_object( file
);
494 allow_fd_caching( file
->fd
);
498 static void named_pipe_device_destroy( struct object
*obj
)
500 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
501 assert( obj
->ops
== &named_pipe_device_ops
);
502 free( device
->pipes
);
505 struct object
*create_named_pipe_device( struct object
*root
, const struct unicode_str
*name
)
507 struct named_pipe_device
*dev
;
509 if ((dev
= create_named_object( root
, &named_pipe_device_ops
, name
, 0, NULL
)) &&
510 get_error() != STATUS_OBJECT_NAME_EXISTS
)
513 if (!(dev
->pipes
= create_namespace( 7 )))
515 release_object( dev
);
522 static void named_pipe_device_file_dump( struct object
*obj
, int verbose
)
524 struct named_pipe_device_file
*file
= (struct named_pipe_device_file
*)obj
;
526 fprintf( stderr
, "File on named pipe device %p\n", file
->device
);
529 static struct fd
*named_pipe_device_file_get_fd( struct object
*obj
)
531 struct named_pipe_device_file
*file
= (struct named_pipe_device_file
*)obj
;
532 return (struct fd
*)grab_object( file
->fd
);
535 static enum server_fd_type
named_pipe_device_file_get_fd_type( struct fd
*fd
)
537 return FD_TYPE_DEVICE
;
540 static void named_pipe_device_file_destroy( struct object
*obj
)
542 struct named_pipe_device_file
*file
= (struct named_pipe_device_file
*)obj
;
543 assert( obj
->ops
== &named_pipe_device_file_ops
);
544 if (file
->fd
) release_object( file
->fd
);
545 release_object( file
->device
);
548 static int pipe_end_flush( struct fd
*fd
, struct async
*async
)
550 struct pipe_end
*pipe_end
= get_fd_user( fd
);
554 set_error( STATUS_PIPE_DISCONNECTED
);
558 if (pipe_end
->connection
&& !list_empty( &pipe_end
->connection
->message_queue
))
560 fd_queue_async( pipe_end
->fd
, async
, ASYNC_TYPE_WAIT
);
561 set_error( STATUS_PENDING
);
566 static void pipe_end_get_file_info( struct fd
*fd
, obj_handle_t handle
, unsigned int info_class
)
568 struct pipe_end
*pipe_end
= get_fd_user( fd
);
569 struct named_pipe
*pipe
= pipe_end
->pipe
;
573 case FileNameInformation
:
575 FILE_NAME_INFORMATION
*name_info
;
576 data_size_t name_len
, reply_size
;
579 if (get_reply_max_size() < sizeof(*name_info
))
581 set_error( STATUS_INFO_LENGTH_MISMATCH
);
585 /* FIXME: We should be able to return on unlinked pipe */
586 if (!pipe
|| !(name
= get_object_name( &pipe
->obj
, &name_len
)))
588 set_error( STATUS_PIPE_DISCONNECTED
);
592 reply_size
= offsetof( FILE_NAME_INFORMATION
, FileName
[name_len
/sizeof(WCHAR
) + 1] );
593 if (reply_size
> get_reply_max_size())
595 reply_size
= get_reply_max_size();
596 set_error( STATUS_BUFFER_OVERFLOW
);
599 if (!(name_info
= set_reply_data_size( reply_size
))) return;
600 name_info
->FileNameLength
= name_len
+ sizeof(WCHAR
);
601 name_info
->FileName
[0] = '\\';
602 reply_size
-= offsetof( FILE_NAME_INFORMATION
, FileName
[1] );
603 if (reply_size
) memcpy( &name_info
->FileName
[1], name
, reply_size
);
606 case FilePipeInformation
:
608 FILE_PIPE_INFORMATION
*pipe_info
;
610 if (!(get_handle_access( current
->process
, handle
) & FILE_READ_ATTRIBUTES
))
612 set_error( STATUS_ACCESS_DENIED
);
616 if (get_reply_max_size() < sizeof(*pipe_info
))
618 set_error( STATUS_INFO_LENGTH_MISMATCH
);
624 set_error( STATUS_PIPE_DISCONNECTED
);
628 if (!(pipe_info
= set_reply_data_size( sizeof(*pipe_info
) ))) return;
629 pipe_info
->ReadMode
= (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)
630 ? FILE_PIPE_MESSAGE_MODE
: FILE_PIPE_BYTE_STREAM_MODE
;
631 pipe_info
->CompletionMode
= (pipe_end
->flags
& NAMED_PIPE_NONBLOCKING_MODE
)
632 ? FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION
;
635 case FilePipeLocalInformation
:
637 FILE_PIPE_LOCAL_INFORMATION
*pipe_info
;
639 if (!(get_handle_access( current
->process
, handle
) & FILE_READ_ATTRIBUTES
))
641 set_error( STATUS_ACCESS_DENIED
);
645 if (get_reply_max_size() < sizeof(*pipe_info
))
647 set_error( STATUS_INFO_LENGTH_MISMATCH
);
653 set_error( STATUS_PIPE_DISCONNECTED
);
657 if (!(pipe_info
= set_reply_data_size( sizeof(*pipe_info
) ))) return;
658 pipe_info
->NamedPipeType
= pipe
->message_mode
;
659 switch (pipe
->sharing
)
661 case FILE_SHARE_READ
:
662 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_OUTBOUND
;
664 case FILE_SHARE_WRITE
:
665 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_INBOUND
;
667 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
668 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_FULL_DUPLEX
;
671 pipe_info
->MaximumInstances
= pipe
->maxinstances
;
672 pipe_info
->CurrentInstances
= pipe
->instances
;
673 pipe_info
->InboundQuota
= pipe
->insize
;
674 pipe_info
->ReadDataAvailable
= 0; /* FIXME */
675 pipe_info
->OutboundQuota
= pipe
->outsize
;
676 pipe_info
->WriteQuotaAvailable
= 0; /* FIXME */
677 pipe_info
->NamedPipeState
= pipe_end
->state
;
678 pipe_info
->NamedPipeEnd
= pipe_end
->obj
.ops
== &pipe_server_ops
679 ? FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
683 default_fd_get_file_info( fd
, handle
, info_class
);
687 static struct security_descriptor
*pipe_end_get_sd( struct object
*obj
)
689 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
690 if (pipe_end
->pipe
) return default_get_sd( &pipe_end
->pipe
->obj
);
691 set_error( STATUS_PIPE_DISCONNECTED
);
695 static int pipe_end_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
696 unsigned int set_info
)
698 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
699 if (pipe_end
->pipe
) return default_set_sd( &pipe_end
->pipe
->obj
, sd
, set_info
);
700 set_error( STATUS_PIPE_DISCONNECTED
);
704 static void pipe_end_get_volume_info( struct fd
*fd
, unsigned int info_class
)
708 case FileFsDeviceInformation
:
710 static const FILE_FS_DEVICE_INFORMATION device_info
=
712 FILE_DEVICE_NAMED_PIPE
,
713 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
715 if (get_reply_max_size() >= sizeof(device_info
))
716 set_reply_data( &device_info
, sizeof(device_info
) );
718 set_error( STATUS_BUFFER_TOO_SMALL
);
722 set_error( STATUS_NOT_IMPLEMENTED
);
726 static void message_queue_read( struct pipe_end
*pipe_end
, struct iosb
*iosb
)
728 struct pipe_message
*message
;
730 if (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)
732 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
733 iosb
->out_size
= min( iosb
->out_size
, message
->iosb
->in_size
- message
->read_pos
);
734 iosb
->status
= message
->read_pos
+ iosb
->out_size
< message
->iosb
->in_size
735 ? STATUS_BUFFER_OVERFLOW
: STATUS_SUCCESS
;
739 data_size_t avail
= 0;
740 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
742 avail
+= message
->iosb
->in_size
- message
->read_pos
;
743 if (avail
>= iosb
->out_size
) break;
745 iosb
->out_size
= min( iosb
->out_size
, avail
);
746 iosb
->status
= STATUS_SUCCESS
;
749 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
750 if (!message
->read_pos
&& message
->iosb
->in_size
== iosb
->out_size
) /* fast path */
752 iosb
->out_data
= message
->iosb
->in_data
;
753 message
->iosb
->in_data
= NULL
;
754 wake_message( message
);
755 free_message( message
);
759 data_size_t write_pos
= 0, writing
;
762 if (iosb
->out_size
&& !(buf
= iosb
->out_data
= malloc( iosb
->out_size
)))
765 iosb
->status
= STATUS_NO_MEMORY
;
771 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
772 writing
= min( iosb
->out_size
- write_pos
, message
->iosb
->in_size
- message
->read_pos
);
773 if (writing
) memcpy( buf
+ write_pos
, (const char *)message
->iosb
->in_data
+ message
->read_pos
, writing
);
774 write_pos
+= writing
;
775 message
->read_pos
+= writing
;
776 if (message
->read_pos
== message
->iosb
->in_size
)
778 wake_message(message
);
779 free_message(message
);
781 } while (write_pos
< iosb
->out_size
);
783 iosb
->result
= iosb
->out_size
;
786 /* We call async_terminate in our reselect implementation, which causes recursive reselect.
787 * We're not interested in such reselect calls, so we ignore them. */
788 static int ignore_reselect
;
790 static void reselect_write_queue( struct pipe_end
*pipe_end
);
792 static void reselect_read_queue( struct pipe_end
*pipe_end
)
799 while (!list_empty( &pipe_end
->message_queue
) && (async
= find_pending_async( &pipe_end
->read_q
)))
801 iosb
= async_get_iosb( async
);
802 message_queue_read( pipe_end
, iosb
);
803 async_terminate( async
, iosb
->result
? STATUS_ALERTED
: iosb
->status
);
804 release_object( async
);
805 release_object( iosb
);
810 if (pipe_end
->connection
)
812 if (list_empty( &pipe_end
->message_queue
))
813 fd_async_wake_up( pipe_end
->connection
->fd
, ASYNC_TYPE_WAIT
, STATUS_SUCCESS
);
815 reselect_write_queue( pipe_end
->connection
);
819 static void reselect_write_queue( struct pipe_end
*pipe_end
)
821 struct pipe_message
*message
, *next
;
822 struct pipe_end
*reader
= pipe_end
->connection
;
823 data_size_t avail
= 0;
829 LIST_FOR_EACH_ENTRY_SAFE( message
, next
, &reader
->message_queue
, struct pipe_message
, entry
)
831 if (message
->async
&& message
->iosb
->status
!= STATUS_PENDING
)
833 release_object( message
->async
);
834 message
->async
= NULL
;
835 free_message( message
);
839 avail
+= message
->iosb
->in_size
- message
->read_pos
;
840 if (message
->async
&& (avail
<= reader
->buffer_size
|| !message
->iosb
->in_size
))
841 wake_message( message
);
846 reselect_read_queue( reader
);
849 static int pipe_end_read( struct fd
*fd
, struct async
*async
, file_pos_t pos
)
851 struct pipe_end
*pipe_end
= get_fd_user( fd
);
853 switch (pipe_end
->state
)
855 case FILE_PIPE_CONNECTED_STATE
:
857 case FILE_PIPE_DISCONNECTED_STATE
:
858 set_error( STATUS_PIPE_DISCONNECTED
);
860 case FILE_PIPE_LISTENING_STATE
:
861 set_error( STATUS_PIPE_LISTENING
);
863 case FILE_PIPE_CLOSING_STATE
:
864 if (!list_empty( &pipe_end
->message_queue
)) break;
865 set_error( STATUS_PIPE_BROKEN
);
869 queue_async( &pipe_end
->read_q
, async
);
870 reselect_read_queue( pipe_end
);
871 set_error( STATUS_PENDING
);
875 static int pipe_end_write( struct fd
*fd
, struct async
*async
, file_pos_t pos
)
877 struct pipe_end
*pipe_end
= get_fd_user( fd
);
878 struct pipe_message
*message
;
881 switch (pipe_end
->state
)
883 case FILE_PIPE_CONNECTED_STATE
:
885 case FILE_PIPE_DISCONNECTED_STATE
:
886 set_error( STATUS_PIPE_DISCONNECTED
);
888 case FILE_PIPE_LISTENING_STATE
:
889 set_error( STATUS_PIPE_LISTENING
);
891 case FILE_PIPE_CLOSING_STATE
:
892 set_error( STATUS_PIPE_CLOSING
);
896 if (!pipe_end
->pipe
->message_mode
&& !get_req_data_size()) return 1;
898 iosb
= async_get_iosb( async
);
899 message
= queue_message( pipe_end
->connection
, iosb
);
900 release_object( iosb
);
901 if (!message
) return 0;
903 message
->async
= (struct async
*)grab_object( async
);
904 queue_async( &pipe_end
->write_q
, async
);
905 reselect_write_queue( pipe_end
);
906 set_error( STATUS_PENDING
);
910 static void pipe_end_reselect_async( struct fd
*fd
, struct async_queue
*queue
)
912 struct pipe_end
*pipe_end
= get_fd_user( fd
);
914 if (ignore_reselect
) return;
916 if (&pipe_end
->write_q
== queue
)
917 reselect_write_queue( pipe_end
);
918 else if (&pipe_end
->read_q
== queue
)
919 reselect_read_queue( pipe_end
);
922 static enum server_fd_type
pipe_end_get_fd_type( struct fd
*fd
)
927 static int pipe_end_peek( struct pipe_end
*pipe_end
)
929 unsigned reply_size
= get_reply_max_size();
930 FILE_PIPE_PEEK_BUFFER
*buffer
;
931 struct pipe_message
*message
;
932 data_size_t avail
= 0;
933 data_size_t message_length
= 0;
935 if (reply_size
< offsetof( FILE_PIPE_PEEK_BUFFER
, Data
))
937 set_error( STATUS_INFO_LENGTH_MISMATCH
);
940 reply_size
-= offsetof( FILE_PIPE_PEEK_BUFFER
, Data
);
942 switch (pipe_end
->state
)
944 case FILE_PIPE_CONNECTED_STATE
:
946 case FILE_PIPE_CLOSING_STATE
:
947 if (!list_empty( &pipe_end
->message_queue
)) break;
948 set_error( STATUS_PIPE_BROKEN
);
951 set_error( pipe_end
->pipe
? STATUS_INVALID_PIPE_STATE
: STATUS_PIPE_DISCONNECTED
);
955 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
956 avail
+= message
->iosb
->in_size
- message
->read_pos
;
957 reply_size
= min( reply_size
, avail
);
959 if (avail
&& pipe_end
->pipe
->message_mode
)
961 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
962 message_length
= message
->iosb
->in_size
- message
->read_pos
;
963 reply_size
= min( reply_size
, message_length
);
966 if (!(buffer
= set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER
, Data
[reply_size
] )))) return 0;
967 buffer
->NamedPipeState
= pipe_end
->state
;
968 buffer
->ReadDataAvailable
= avail
;
969 buffer
->NumberOfMessages
= 0; /* FIXME */
970 buffer
->MessageLength
= message_length
;
974 data_size_t write_pos
= 0, writing
;
975 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
977 writing
= min( reply_size
- write_pos
, message
->iosb
->in_size
- message
->read_pos
);
978 memcpy( buffer
->Data
+ write_pos
, (const char *)message
->iosb
->in_data
+ message
->read_pos
,
980 write_pos
+= writing
;
981 if (write_pos
== reply_size
) break;
984 if (message_length
> reply_size
) set_error( STATUS_BUFFER_OVERFLOW
);
988 static int pipe_end_transceive( struct pipe_end
*pipe_end
, struct async
*async
)
990 struct pipe_message
*message
;
993 if (!pipe_end
->connection
)
995 set_error( pipe_end
->pipe
? STATUS_INVALID_PIPE_STATE
: STATUS_PIPE_DISCONNECTED
);
999 if (!(pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
))
1001 set_error( STATUS_INVALID_READ_MODE
);
1005 /* not allowed if we already have read data buffered */
1006 if (!list_empty( &pipe_end
->message_queue
))
1008 set_error( STATUS_PIPE_BUSY
);
1012 iosb
= async_get_iosb( async
);
1013 /* ignore output buffer copy transferred because of METHOD_NEITHER */
1014 iosb
->in_size
-= iosb
->out_size
;
1015 /* transaction never blocks on write, so just queue a message without async */
1016 message
= queue_message( pipe_end
->connection
, iosb
);
1017 release_object( iosb
);
1018 if (!message
) return 0;
1019 reselect_read_queue( pipe_end
->connection
);
1021 queue_async( &pipe_end
->read_q
, async
);
1022 reselect_read_queue( pipe_end
);
1023 set_error( STATUS_PENDING
);
1027 static int pipe_end_get_connection_attribute( struct pipe_end
*pipe_end
)
1029 const char *attr
= get_req_data();
1030 data_size_t value_size
, attr_size
= get_req_data_size();
1033 if (attr_size
== sizeof("ClientProcessId") && !memcmp( attr
, "ClientProcessId", attr_size
))
1035 value
= &pipe_end
->client_pid
;
1036 value_size
= sizeof(pipe_end
->client_pid
);
1038 else if (attr_size
== sizeof("ServerProcessId") && !memcmp( attr
, "ServerProcessId", attr_size
))
1040 value
= &pipe_end
->server_pid
;
1041 value_size
= sizeof(pipe_end
->server_pid
);
1045 set_error( STATUS_ILLEGAL_FUNCTION
);
1049 if (get_reply_max_size() < value_size
)
1051 set_error( STATUS_INFO_LENGTH_MISMATCH
);
1055 set_reply_data( value
, value_size
);
1059 static int pipe_end_ioctl( struct pipe_end
*pipe_end
, ioctl_code_t code
, struct async
*async
)
1063 case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE
:
1064 return pipe_end_get_connection_attribute( pipe_end
);
1066 case FSCTL_PIPE_PEEK
:
1067 return pipe_end_peek( pipe_end
);
1069 case FSCTL_PIPE_TRANSCEIVE
:
1070 return pipe_end_transceive( pipe_end
, async
);
1073 return default_fd_ioctl( pipe_end
->fd
, code
, async
);
1077 static int pipe_server_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1079 struct pipe_server
*server
= get_fd_user( fd
);
1083 case FSCTL_PIPE_LISTEN
:
1084 switch(server
->pipe_end
.state
)
1086 case FILE_PIPE_LISTENING_STATE
:
1087 case FILE_PIPE_DISCONNECTED_STATE
:
1089 case FILE_PIPE_CONNECTED_STATE
:
1090 set_error( STATUS_PIPE_CONNECTED
);
1092 case FILE_PIPE_CLOSING_STATE
:
1093 set_error( STATUS_PIPE_CLOSING
);
1097 server
->pipe_end
.state
= FILE_PIPE_LISTENING_STATE
;
1098 queue_async( &server
->listen_q
, async
);
1099 async_wake_up( &server
->pipe_end
.pipe
->waiters
, STATUS_SUCCESS
);
1100 set_error( STATUS_PENDING
);
1103 case FSCTL_PIPE_DISCONNECT
:
1104 switch(server
->pipe_end
.state
)
1106 case FILE_PIPE_CONNECTED_STATE
:
1107 /* dump the client connection - all data is lost */
1108 assert( server
->pipe_end
.connection
);
1109 release_object( server
->pipe_end
.connection
->pipe
);
1110 server
->pipe_end
.connection
->pipe
= NULL
;
1112 case FILE_PIPE_CLOSING_STATE
:
1114 case FILE_PIPE_LISTENING_STATE
:
1115 set_error( STATUS_PIPE_LISTENING
);
1117 case FILE_PIPE_DISCONNECTED_STATE
:
1118 set_error( STATUS_PIPE_DISCONNECTED
);
1122 pipe_end_disconnect( &server
->pipe_end
, STATUS_PIPE_DISCONNECTED
);
1126 return pipe_end_ioctl( &server
->pipe_end
, code
, async
);
1130 static int pipe_client_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1132 struct pipe_end
*client
= get_fd_user( fd
);
1136 case FSCTL_PIPE_LISTEN
:
1137 set_error( STATUS_ILLEGAL_FUNCTION
);
1141 return pipe_end_ioctl( client
, code
, async
);
1145 static void init_pipe_end( struct pipe_end
*pipe_end
, struct named_pipe
*pipe
,
1146 unsigned int pipe_flags
, data_size_t buffer_size
)
1148 pipe_end
->pipe
= (struct named_pipe
*)grab_object( pipe
);
1149 pipe_end
->fd
= NULL
;
1150 pipe_end
->flags
= pipe_flags
;
1151 pipe_end
->connection
= NULL
;
1152 pipe_end
->buffer_size
= buffer_size
;
1153 init_async_queue( &pipe_end
->read_q
);
1154 init_async_queue( &pipe_end
->write_q
);
1155 list_init( &pipe_end
->message_queue
);
1158 static struct pipe_server
*create_pipe_server( struct named_pipe
*pipe
, unsigned int options
,
1159 unsigned int pipe_flags
)
1161 struct pipe_server
*server
;
1163 server
= alloc_object( &pipe_server_ops
);
1167 server
->options
= options
;
1168 init_pipe_end( &server
->pipe_end
, pipe
, pipe_flags
, pipe
->insize
);
1169 server
->pipe_end
.state
= FILE_PIPE_LISTENING_STATE
;
1170 server
->pipe_end
.server_pid
= get_process_id( current
->process
);
1171 init_async_queue( &server
->listen_q
);
1173 list_add_head( &pipe
->servers
, &server
->entry
);
1174 if (!(server
->pipe_end
.fd
= alloc_pseudo_fd( &pipe_server_fd_ops
, &server
->pipe_end
.obj
, options
)))
1176 release_object( server
);
1179 allow_fd_caching( server
->pipe_end
.fd
);
1180 set_fd_signaled( server
->pipe_end
.fd
, 1 );
1184 static struct pipe_end
*create_pipe_client( struct named_pipe
*pipe
, data_size_t buffer_size
, unsigned int options
)
1186 struct pipe_end
*client
;
1188 client
= alloc_object( &pipe_client_ops
);
1192 init_pipe_end( client
, pipe
, 0, buffer_size
);
1193 client
->state
= FILE_PIPE_CONNECTED_STATE
;
1194 client
->client_pid
= get_process_id( current
->process
);
1196 client
->fd
= alloc_pseudo_fd( &pipe_client_fd_ops
, &client
->obj
, options
);
1199 release_object( client
);
1202 allow_fd_caching( client
->fd
);
1203 set_fd_signaled( client
->fd
, 1 );
1208 static struct pipe_server
*find_available_server( struct named_pipe
*pipe
)
1210 struct pipe_server
*server
;
1212 /* look for pipe servers that are listening */
1213 LIST_FOR_EACH_ENTRY( server
, &pipe
->servers
, struct pipe_server
, entry
)
1215 if (server
->pipe_end
.state
== FILE_PIPE_LISTENING_STATE
&& async_queued( &server
->listen_q
))
1216 return (struct pipe_server
*)grab_object( server
);
1219 /* fall back to pipe servers that are idle */
1220 LIST_FOR_EACH_ENTRY( server
, &pipe
->servers
, struct pipe_server
, entry
)
1222 if (server
->pipe_end
.state
== FILE_PIPE_LISTENING_STATE
)
1223 return (struct pipe_server
*)grab_object( server
);
1229 static int named_pipe_link_name( struct object
*obj
, struct object_name
*name
, struct object
*parent
)
1231 struct named_pipe_device
*dev
= (struct named_pipe_device
*)parent
;
1233 if (parent
->ops
!= &named_pipe_device_ops
)
1235 set_error( STATUS_OBJECT_NAME_INVALID
);
1238 namespace_add( dev
->pipes
, name
);
1239 name
->parent
= grab_object( parent
);
1243 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
1244 unsigned int sharing
, unsigned int options
)
1246 struct named_pipe
*pipe
= (struct named_pipe
*)obj
;
1247 struct pipe_server
*server
;
1248 struct pipe_end
*client
;
1249 unsigned int pipe_sharing
;
1251 if (!(server
= find_available_server( pipe
)))
1253 set_error( STATUS_PIPE_NOT_AVAILABLE
);
1257 pipe_sharing
= pipe
->sharing
;
1258 if (((access
& GENERIC_READ
) && !(pipe_sharing
& FILE_SHARE_READ
)) ||
1259 ((access
& GENERIC_WRITE
) && !(pipe_sharing
& FILE_SHARE_WRITE
)))
1261 set_error( STATUS_ACCESS_DENIED
);
1262 release_object( server
);
1266 if ((client
= create_pipe_client( pipe
, pipe
->outsize
, options
)))
1268 async_wake_up( &server
->listen_q
, STATUS_SUCCESS
);
1269 server
->pipe_end
.state
= FILE_PIPE_CONNECTED_STATE
;
1270 server
->pipe_end
.connection
= client
;
1271 client
->connection
= &server
->pipe_end
;
1272 server
->pipe_end
.client_pid
= client
->client_pid
;
1273 client
->server_pid
= server
->pipe_end
.server_pid
;
1275 release_object( server
);
1276 return &client
->obj
;
1279 static int named_pipe_device_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1281 struct named_pipe_device
*device
= get_fd_user( fd
);
1285 case FSCTL_PIPE_WAIT
:
1287 const FILE_PIPE_WAIT_FOR_BUFFER
*buffer
= get_req_data();
1288 data_size_t size
= get_req_data_size();
1289 struct named_pipe
*pipe
;
1290 struct pipe_server
*server
;
1291 struct unicode_str name
;
1294 if (size
< sizeof(*buffer
) ||
1295 size
< FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER
, Name
[buffer
->NameLength
/sizeof(WCHAR
)]))
1297 set_error( STATUS_INVALID_PARAMETER
);
1300 name
.str
= buffer
->Name
;
1301 name
.len
= (buffer
->NameLength
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
1302 if (!(pipe
= open_named_object( &device
->obj
, &named_pipe_ops
, &name
, 0 ))) return 0;
1304 if (!(server
= find_available_server( pipe
)))
1306 queue_async( &pipe
->waiters
, async
);
1307 when
= buffer
->TimeoutSpecified
? buffer
->Timeout
.QuadPart
: pipe
->timeout
;
1308 async_set_timeout( async
, when
, STATUS_IO_TIMEOUT
);
1309 release_object( pipe
);
1310 set_error( STATUS_PENDING
);
1314 release_object( server
);
1315 release_object( pipe
);
1320 return default_fd_ioctl( fd
, code
, async
);
1325 DECL_HANDLER(create_named_pipe
)
1327 struct named_pipe
*pipe
;
1328 struct pipe_server
*server
;
1329 struct unicode_str name
;
1330 struct object
*root
;
1331 const struct security_descriptor
*sd
;
1332 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, &root
);
1334 if (!objattr
) return;
1336 if (!req
->sharing
|| (req
->sharing
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1337 (!(req
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) && (req
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)))
1339 if (root
) release_object( root
);
1340 set_error( STATUS_INVALID_PARAMETER
);
1344 if (!name
.len
) /* pipes need a root directory even without a name */
1346 if (!objattr
->rootdir
)
1348 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD
);
1351 if (!(root
= get_directory_obj( current
->process
, objattr
->rootdir
))) return;
1354 pipe
= create_named_object( root
, &named_pipe_ops
, &name
, objattr
->attributes
| OBJ_OPENIF
, NULL
);
1356 if (root
) release_object( root
);
1359 if (get_error() != STATUS_OBJECT_NAME_EXISTS
)
1361 /* initialize it if it didn't already exist */
1362 pipe
->instances
= 0;
1363 init_async_queue( &pipe
->waiters
);
1364 list_init( &pipe
->servers
);
1365 pipe
->insize
= req
->insize
;
1366 pipe
->outsize
= req
->outsize
;
1367 pipe
->maxinstances
= req
->maxinstances
;
1368 pipe
->timeout
= req
->timeout
;
1369 pipe
->message_mode
= (req
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) != 0;
1370 pipe
->sharing
= req
->sharing
;
1371 if (sd
) default_set_sd( &pipe
->obj
, sd
, OWNER_SECURITY_INFORMATION
|
1372 GROUP_SECURITY_INFORMATION
|
1373 DACL_SECURITY_INFORMATION
|
1374 SACL_SECURITY_INFORMATION
);
1378 if (pipe
->maxinstances
<= pipe
->instances
)
1380 set_error( STATUS_INSTANCE_NOT_AVAILABLE
);
1381 release_object( pipe
);
1384 if (pipe
->sharing
!= req
->sharing
)
1386 set_error( STATUS_ACCESS_DENIED
);
1387 release_object( pipe
);
1390 clear_error(); /* clear the name collision */
1393 server
= create_pipe_server( pipe
, req
->options
, req
->flags
);
1396 reply
->handle
= alloc_handle( current
->process
, server
, req
->access
, objattr
->attributes
);
1398 release_object( server
);
1401 release_object( pipe
);
1404 DECL_HANDLER(set_named_pipe_info
)
1406 struct pipe_end
*pipe_end
;
1408 pipe_end
= (struct pipe_end
*)get_handle_obj( current
->process
, req
->handle
,
1409 FILE_WRITE_ATTRIBUTES
, &pipe_server_ops
);
1412 if (get_error() != STATUS_OBJECT_TYPE_MISMATCH
)
1416 pipe_end
= (struct pipe_end
*)get_handle_obj( current
->process
, req
->handle
,
1417 0, &pipe_client_ops
);
1418 if (!pipe_end
) return;
1421 if (!pipe_end
->pipe
)
1423 set_error( STATUS_PIPE_DISCONNECTED
);
1425 else if ((req
->flags
& ~(NAMED_PIPE_MESSAGE_STREAM_READ
| NAMED_PIPE_NONBLOCKING_MODE
)) ||
1426 ((req
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
) && !pipe_end
->pipe
->message_mode
))
1428 set_error( STATUS_INVALID_PARAMETER
);
1432 pipe_end
->flags
= req
->flags
;
1435 release_object( pipe_end
);