oledb32/tests: Avoid "misleading indentation" warnings.
[wine.git] / server / console.c
blob5407fba14116cea12443a49363c0ac08f388f521
1 /*
2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
5 * 2001 Eric Pouech
6 * Copyright 2020 Jacek Caban for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
26 #include <assert.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <signal.h>
31 #include <sys/ioctl.h>
32 #include <termios.h>
34 #include "ntstatus.h"
35 #define WIN32_NO_STATUS
36 #include "handle.h"
37 #include "process.h"
38 #include "request.h"
39 #include "file.h"
40 #include "unicode.h"
41 #include "wincon.h"
42 #include "winternl.h"
43 #include "wine/condrv.h"
45 struct screen_buffer;
47 struct history_line
49 data_size_t len;
50 WCHAR text[1];
53 struct console
55 struct object obj; /* object header */
56 int signaled; /* is console signaled */
57 struct thread *renderer; /* console renderer thread */
58 struct screen_buffer *active; /* active screen buffer */
59 struct console_server *server; /* console server object */
60 unsigned int last_id; /* id of last created console buffer */
61 struct fd *fd; /* for bare console, attached input fd */
62 struct async_queue ioctl_q; /* ioctl queue */
63 struct async_queue read_q; /* read queue */
66 static void console_dump( struct object *obj, int verbose );
67 static void console_destroy( struct object *obj );
68 static int console_signaled( struct object *obj, struct wait_queue_entry *entry );
69 static struct fd *console_get_fd( struct object *obj );
70 static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
71 unsigned int attr, struct object *root );
72 static struct object *console_open_file( struct object *obj, unsigned int access,
73 unsigned int sharing, unsigned int options );
74 static int console_add_queue( struct object *obj, struct wait_queue_entry *entry );
76 static const struct object_ops console_ops =
78 sizeof(struct console), /* size */
79 &file_type, /* type */
80 console_dump, /* dump */
81 console_add_queue, /* add_queue */
82 remove_queue, /* remove_queue */
83 console_signaled, /* signaled */
84 no_satisfied, /* satisfied */
85 no_signal, /* signal */
86 console_get_fd, /* get_fd */
87 default_map_access, /* map_access */
88 default_get_sd, /* get_sd */
89 default_set_sd, /* set_sd */
90 no_get_full_name, /* get_full_name */
91 console_lookup_name, /* lookup_name */
92 no_link_name, /* link_name */
93 NULL, /* unlink_name */
94 console_open_file, /* open_file */
95 no_kernel_obj_list, /* get_kernel_obj_list */
96 no_close_handle, /* close_handle */
97 console_destroy /* destroy */
100 static enum server_fd_type console_get_fd_type( struct fd *fd );
101 static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
102 static void console_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class );
103 static void console_read( struct fd *fd, struct async *async, file_pos_t pos );
104 static void console_flush( struct fd *fd, struct async *async );
105 static void console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
107 static const struct fd_ops console_fd_ops =
109 default_fd_get_poll_events, /* get_poll_events */
110 default_poll_event, /* poll_event */
111 console_get_fd_type, /* get_fd_type */
112 console_read, /* read */
113 no_fd_write, /* write */
114 console_flush, /* flush */
115 console_get_file_info, /* get_file_info */
116 console_get_volume_info, /* get_volume_info */
117 console_ioctl, /* ioctl */
118 default_fd_cancel_async, /* cancel_async */
119 default_fd_queue_async, /* queue_async */
120 default_fd_reselect_async /* reselect_async */
123 struct console_host_ioctl
125 unsigned int code; /* ioctl code */
126 int output; /* output id for screen buffer ioctls */
127 struct async *async; /* ioctl async */
128 struct list entry; /* list entry */
131 struct console_server
133 struct object obj; /* object header */
134 struct fd *fd; /* pseudo-fd for ioctls */
135 struct console *console; /* attached console */
136 struct list queue; /* ioctl queue */
137 struct list read_queue; /* blocking read queue */
138 unsigned int busy : 1; /* flag if server processing an ioctl */
139 unsigned int once_input : 1; /* flag if input thread has already been requested */
140 int term_fd; /* UNIX terminal fd */
141 struct termios termios; /* original termios */
144 static void console_server_dump( struct object *obj, int verbose );
145 static void console_server_destroy( struct object *obj );
146 static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry );
147 static struct fd *console_server_get_fd( struct object *obj );
148 static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
149 unsigned int attr, struct object *root );
150 static struct object *console_server_open_file( struct object *obj, unsigned int access,
151 unsigned int sharing, unsigned int options );
153 static const struct object_ops console_server_ops =
155 sizeof(struct console_server), /* size */
156 &file_type, /* type */
157 console_server_dump, /* dump */
158 add_queue, /* add_queue */
159 remove_queue, /* remove_queue */
160 console_server_signaled, /* signaled */
161 no_satisfied, /* satisfied */
162 no_signal, /* signal */
163 console_server_get_fd, /* get_fd */
164 default_map_access, /* map_access */
165 default_get_sd, /* get_sd */
166 default_set_sd, /* set_sd */
167 no_get_full_name, /* get_full_name */
168 console_server_lookup_name, /* lookup_name */
169 no_link_name, /* link_name */
170 NULL, /* unlink_name */
171 console_server_open_file, /* open_file */
172 no_kernel_obj_list, /* get_kernel_obj_list */
173 no_close_handle, /* close_handle */
174 console_server_destroy /* destroy */
177 static void console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
179 static const struct fd_ops console_server_fd_ops =
181 default_fd_get_poll_events, /* get_poll_events */
182 default_poll_event, /* poll_event */
183 console_get_fd_type, /* get_fd_type */
184 no_fd_read, /* read */
185 no_fd_write, /* write */
186 no_fd_flush, /* flush */
187 no_fd_get_file_info, /* get_file_info */
188 no_fd_get_volume_info, /* get_volume_info */
189 console_server_ioctl, /* ioctl */
190 default_fd_cancel_async, /* cancel_async */
191 default_fd_queue_async, /* queue_async */
192 default_fd_reselect_async /* reselect_async */
195 struct font_info
197 short int width;
198 short int height;
199 short int weight;
200 short int pitch_family;
201 WCHAR *face_name;
202 data_size_t face_len;
205 struct screen_buffer
207 struct object obj; /* object header */
208 struct list entry; /* entry in list of all screen buffers */
209 struct console *input; /* associated console input */
210 unsigned int id; /* buffer id */
211 struct fd *fd; /* for bare console, attached output fd */
212 struct async_queue ioctl_q; /* ioctl queue */
215 static void screen_buffer_dump( struct object *obj, int verbose );
216 static void screen_buffer_destroy( struct object *obj );
217 static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry );
218 static struct fd *screen_buffer_get_fd( struct object *obj );
219 static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
220 unsigned int sharing, unsigned int options );
222 static const struct object_ops screen_buffer_ops =
224 sizeof(struct screen_buffer), /* size */
225 &file_type, /* type */
226 screen_buffer_dump, /* dump */
227 screen_buffer_add_queue, /* add_queue */
228 NULL, /* remove_queue */
229 NULL, /* signaled */
230 NULL, /* satisfied */
231 no_signal, /* signal */
232 screen_buffer_get_fd, /* get_fd */
233 default_map_access, /* map_access */
234 default_get_sd, /* get_sd */
235 default_set_sd, /* set_sd */
236 no_get_full_name, /* get_full_name */
237 no_lookup_name, /* lookup_name */
238 no_link_name, /* link_name */
239 NULL, /* unlink_name */
240 screen_buffer_open_file, /* open_file */
241 no_kernel_obj_list, /* get_kernel_obj_list */
242 no_close_handle, /* close_handle */
243 screen_buffer_destroy /* destroy */
246 static void screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos );
247 static void screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
249 static const struct fd_ops screen_buffer_fd_ops =
251 default_fd_get_poll_events, /* get_poll_events */
252 default_poll_event, /* poll_event */
253 console_get_fd_type, /* get_fd_type */
254 no_fd_read, /* read */
255 screen_buffer_write, /* write */
256 no_fd_flush, /* flush */
257 console_get_file_info, /* get_file_info */
258 console_get_volume_info, /* get_volume_info */
259 screen_buffer_ioctl, /* ioctl */
260 default_fd_cancel_async, /* cancel_async */
261 default_fd_queue_async, /* queue_async */
262 default_fd_reselect_async /* reselect_async */
265 static void console_device_dump( struct object *obj, int verbose );
266 static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
267 unsigned int attr, struct object *root );
268 static struct object *console_device_open_file( struct object *obj, unsigned int access,
269 unsigned int sharing, unsigned int options );
271 static const struct object_ops console_device_ops =
273 sizeof(struct object), /* size */
274 &device_type, /* type */
275 console_device_dump, /* dump */
276 no_add_queue, /* add_queue */
277 NULL, /* remove_queue */
278 NULL, /* signaled */
279 no_satisfied, /* satisfied */
280 no_signal, /* signal */
281 no_get_fd, /* get_fd */
282 default_map_access, /* map_access */
283 default_get_sd, /* get_sd */
284 default_set_sd, /* set_sd */
285 default_get_full_name, /* get_full_name */
286 console_device_lookup_name, /* lookup_name */
287 directory_link_name, /* link_name */
288 default_unlink_name, /* unlink_name */
289 console_device_open_file, /* open_file */
290 no_kernel_obj_list, /* get_kernel_obj_list */
291 no_close_handle, /* close_handle */
292 no_destroy /* destroy */
295 struct console_input
297 struct object obj; /* object header */
298 struct fd *fd; /* pseudo-fd */
301 static void console_input_dump( struct object *obj, int verbose );
302 static struct object *console_input_open_file( struct object *obj, unsigned int access,
303 unsigned int sharing, unsigned int options );
304 static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry );
305 static struct fd *console_input_get_fd( struct object *obj );
306 static void console_input_destroy( struct object *obj );
308 static const struct object_ops console_input_ops =
310 sizeof(struct console_input), /* size */
311 &device_type, /* type */
312 console_input_dump, /* dump */
313 console_input_add_queue, /* add_queue */
314 NULL, /* remove_queue */
315 NULL, /* signaled */
316 no_satisfied, /* satisfied */
317 no_signal, /* signal */
318 console_input_get_fd, /* get_fd */
319 default_map_access, /* map_access */
320 default_get_sd, /* get_sd */
321 default_set_sd, /* set_sd */
322 no_get_full_name, /* get_full_name */
323 no_lookup_name, /* lookup_name */
324 directory_link_name, /* link_name */
325 default_unlink_name, /* unlink_name */
326 console_input_open_file, /* open_file */
327 no_kernel_obj_list, /* get_kernel_obj_list */
328 no_close_handle, /* close_handle */
329 console_input_destroy /* destroy */
332 static void console_input_read( struct fd *fd, struct async *async, file_pos_t pos );
333 static void console_input_flush( struct fd *fd, struct async *async );
334 static void console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
336 static const struct fd_ops console_input_fd_ops =
338 default_fd_get_poll_events, /* get_poll_events */
339 default_poll_event, /* poll_event */
340 console_get_fd_type, /* get_fd_type */
341 console_input_read, /* read */
342 no_fd_write, /* write */
343 console_input_flush, /* flush */
344 console_get_file_info, /* get_file_info */
345 console_get_volume_info, /* get_volume_info */
346 console_input_ioctl, /* ioctl */
347 default_fd_cancel_async, /* cancel_async */
348 default_fd_queue_async, /* queue_async */
349 default_fd_reselect_async /* reselect_async */
352 struct console_output
354 struct object obj; /* object header */
355 struct fd *fd; /* pseudo-fd */
358 static void console_output_dump( struct object *obj, int verbose );
359 static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry );
360 static struct fd *console_output_get_fd( struct object *obj );
361 static struct object *console_output_open_file( struct object *obj, unsigned int access,
362 unsigned int sharing, unsigned int options );
363 static void console_output_destroy( struct object *obj );
365 static const struct object_ops console_output_ops =
367 sizeof(struct console_output), /* size */
368 &device_type, /* type */
369 console_output_dump, /* dump */
370 console_output_add_queue, /* add_queue */
371 NULL, /* remove_queue */
372 NULL, /* signaled */
373 no_satisfied, /* satisfied */
374 no_signal, /* signal */
375 console_output_get_fd, /* get_fd */
376 default_map_access, /* map_access */
377 default_get_sd, /* get_sd */
378 default_set_sd, /* set_sd */
379 no_get_full_name, /* get_full_name */
380 no_lookup_name, /* lookup_name */
381 directory_link_name, /* link_name */
382 default_unlink_name, /* unlink_name */
383 console_output_open_file, /* open_file */
384 no_kernel_obj_list, /* get_kernel_obj_list */
385 no_close_handle, /* close_handle */
386 console_output_destroy /* destroy */
389 static void console_output_write( struct fd *fd, struct async *async, file_pos_t pos );
390 static void console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
392 static const struct fd_ops console_output_fd_ops =
394 default_fd_get_poll_events, /* get_poll_events */
395 default_poll_event, /* poll_event */
396 console_get_fd_type, /* get_fd_type */
397 no_fd_read, /* read */
398 console_output_write, /* write */
399 no_fd_flush, /* flush */
400 console_get_file_info, /* get_file_info */
401 console_get_volume_info, /* get_volume_info */
402 console_output_ioctl, /* ioctl */
403 default_fd_cancel_async, /* cancel_async */
404 default_fd_queue_async, /* queue_async */
405 default_fd_reselect_async /* reselect_async */
408 struct console_connection
410 struct object obj; /* object header */
411 struct fd *fd; /* pseudo-fd for ioctls */
414 static void console_connection_dump( struct object *obj, int verbose );
415 static struct fd *console_connection_get_fd( struct object *obj );
416 static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
417 unsigned int attr, struct object *root );
418 static struct object *console_connection_open_file( struct object *obj, unsigned int access,
419 unsigned int sharing, unsigned int options );
420 static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
421 static void console_connection_destroy( struct object *obj );
423 static const struct object_ops console_connection_ops =
425 sizeof(struct console_connection),/* size */
426 &device_type, /* type */
427 console_connection_dump, /* dump */
428 no_add_queue, /* add_queue */
429 NULL, /* remove_queue */
430 NULL, /* signaled */
431 no_satisfied, /* satisfied */
432 no_signal, /* signal */
433 console_connection_get_fd, /* get_fd */
434 default_map_access, /* map_access */
435 default_get_sd, /* get_sd */
436 default_set_sd, /* set_sd */
437 no_get_full_name, /* get_full_name */
438 console_connection_lookup_name, /* lookup_name */
439 directory_link_name, /* link_name */
440 default_unlink_name, /* unlink_name */
441 console_connection_open_file, /* open_file */
442 no_kernel_obj_list, /* get_kernel_obj_list */
443 console_connection_close_handle, /* close_handle */
444 console_connection_destroy /* destroy */
447 static void console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
449 static const struct fd_ops console_connection_fd_ops =
451 default_fd_get_poll_events, /* get_poll_events */
452 default_poll_event, /* poll_event */
453 console_get_fd_type, /* get_fd_type */
454 no_fd_read, /* read */
455 no_fd_write, /* write */
456 no_fd_flush, /* flush */
457 no_fd_get_file_info, /* get_file_info */
458 no_fd_get_volume_info, /* get_volume_info */
459 console_connection_ioctl, /* ioctl */
460 default_fd_cancel_async, /* cancel_async */
461 default_fd_queue_async, /* queue_async */
462 default_fd_reselect_async /* reselect_async */
465 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
467 static int queue_host_ioctl( struct console_server *server, unsigned int code, unsigned int output,
468 struct async *async, struct async_queue *queue );
470 static int console_add_queue( struct object *obj, struct wait_queue_entry *entry )
472 struct console *console = (struct console*)obj;
473 assert( obj->ops == &console_ops );
474 /* before waiting, ensure conhost's input thread has been started */
475 if (console->server && !console->server->once_input)
477 console->server->once_input = 1;
478 if (console->server->term_fd == -1)
479 queue_host_ioctl( console->server, IOCTL_CONDRV_PEEK, 0, NULL, NULL );
481 return add_queue( &console->obj, entry );
484 static int console_signaled( struct object *obj, struct wait_queue_entry *entry )
486 struct console *console = (struct console*)obj;
487 return console->signaled;
490 static struct fd *console_get_fd( struct object *obj )
492 struct console *console = (struct console *)obj;
493 assert( obj->ops == &console_ops );
494 return (struct fd *)grab_object( console->fd );
497 static enum server_fd_type console_get_fd_type( struct fd *fd )
499 return FD_TYPE_CHAR;
502 static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
504 set_error( STATUS_INVALID_DEVICE_REQUEST );
507 static void console_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class )
509 switch (info_class)
511 case FileFsDeviceInformation:
513 static const FILE_FS_DEVICE_INFORMATION device_info =
515 FILE_DEVICE_CONSOLE,
516 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
518 if (get_reply_max_size() >= sizeof(device_info))
519 set_reply_data( &device_info, sizeof(device_info) );
520 else
521 set_error( STATUS_BUFFER_TOO_SMALL );
522 break;
524 default:
525 set_error( STATUS_NOT_IMPLEMENTED );
529 static struct object *create_console(void)
531 struct console *console;
533 if (!(console = alloc_object( &console_ops )))
534 return NULL;
536 console->renderer = NULL;
537 console->signaled = 0;
538 console->active = NULL;
539 console->server = NULL;
540 console->fd = NULL;
541 console->last_id = 0;
542 init_async_queue( &console->ioctl_q );
543 init_async_queue( &console->read_q );
545 console->fd = alloc_pseudo_fd( &console_fd_ops, &console->obj, FILE_SYNCHRONOUS_IO_NONALERT );
546 if (!console->fd)
548 release_object( console );
549 return NULL;
551 allow_fd_caching( console->fd );
552 return &console->obj;
555 static void console_host_ioctl_terminate( struct console_host_ioctl *call, unsigned int status )
557 if (call->async)
559 async_terminate( call->async, status );
560 release_object( call->async );
562 free( call );
565 static int queue_host_ioctl( struct console_server *server, unsigned int code, unsigned int output,
566 struct async *async, struct async_queue *queue )
568 struct console_host_ioctl *ioctl;
570 if (!(ioctl = mem_alloc( sizeof(*ioctl) ))) return 0;
571 ioctl->code = code;
572 ioctl->output = output;
573 ioctl->async = NULL;
574 if (async)
576 ioctl->async = (struct async *)grab_object( async );
577 queue_async( queue, async );
579 list_add_tail( &server->queue, &ioctl->entry );
580 wake_up( &server->obj, 0 );
581 if (async) set_error( STATUS_PENDING );
582 return 1;
585 static void disconnect_console_server( struct console_server *server )
587 while (!list_empty( &server->queue ))
589 struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
590 list_remove( &call->entry );
591 console_host_ioctl_terminate( call, STATUS_CANCELLED );
593 while (!list_empty( &server->read_queue ))
595 struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
596 list_remove( &call->entry );
597 console_host_ioctl_terminate( call, STATUS_CANCELLED );
600 if (server->term_fd != -1)
602 tcsetattr( server->term_fd, TCSANOW, &server->termios );
603 close( server->term_fd );
604 server->term_fd = -1;
607 if (server->console)
609 assert( server->console->server == server );
610 server->console->server = NULL;
611 server->console = NULL;
612 wake_up( &server->obj, 0 );
616 static void set_active_screen_buffer( struct console *console, struct screen_buffer *screen_buffer )
618 if (console->active == screen_buffer) return;
619 if (console->active) release_object( console->active );
620 console->active = (struct screen_buffer *)grab_object( screen_buffer );
622 if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_ACTIVATE,
623 screen_buffer->id, NULL, NULL );
626 static struct object *create_screen_buffer( struct console *console )
628 struct screen_buffer *screen_buffer;
630 if (console->last_id == ~0)
632 set_error( STATUS_NO_MEMORY );
633 return NULL;
636 if (!(screen_buffer = alloc_object( &screen_buffer_ops )))
637 return NULL;
639 screen_buffer->id = ++console->last_id;
640 screen_buffer->input = console;
641 init_async_queue( &screen_buffer->ioctl_q );
642 list_add_head( &screen_buffer_list, &screen_buffer->entry );
644 screen_buffer->fd = alloc_pseudo_fd( &screen_buffer_fd_ops, &screen_buffer->obj,
645 FILE_SYNCHRONOUS_IO_NONALERT );
646 if (!screen_buffer->fd)
648 release_object( screen_buffer );
649 return NULL;
651 allow_fd_caching(screen_buffer->fd);
653 if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_INIT_OUTPUT,
654 screen_buffer->id, NULL, NULL );
655 if (!console->active) set_active_screen_buffer( console, screen_buffer );
656 return &screen_buffer->obj;
659 struct thread *console_get_renderer( struct console *console )
661 return console->renderer;
664 struct console_signal_info
666 struct console *console;
667 process_id_t group;
668 int signal;
671 static int propagate_console_signal_cb(struct process *process, void *user)
673 struct console_signal_info* csi = (struct console_signal_info*)user;
675 if (process->console == csi->console && (!csi->group || process->group_id == csi->group))
677 /* find a suitable thread to signal */
678 struct thread *thread;
679 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
681 if (send_thread_signal( thread, csi->signal )) break;
684 return FALSE;
687 static void propagate_console_signal( struct console *console,
688 int sig, process_id_t group_id )
690 struct console_signal_info csi;
692 if (!console)
694 set_error( STATUS_INVALID_PARAMETER );
695 return;
697 /* FIXME: should support the other events (like CTRL_BREAK) */
698 if (sig != CTRL_C_EVENT)
700 set_error( STATUS_NOT_IMPLEMENTED );
701 return;
703 csi.console = console;
704 csi.signal = SIGINT;
705 csi.group = group_id;
707 enum_processes(propagate_console_signal_cb, &csi);
710 /* dumb dump */
711 static void console_dump( struct object *obj, int verbose )
713 struct console *console = (struct console *)obj;
714 assert( obj->ops == &console_ops );
715 fprintf( stderr, "Console input active=%p server=%p\n",
716 console->active, console->server );
719 static void console_destroy( struct object *obj )
721 struct console *console = (struct console *)obj;
722 struct screen_buffer *curr;
724 assert( obj->ops == &console_ops );
726 if (console->server)
728 assert( console->server->console == console );
729 disconnect_console_server( console->server );
732 if (console->active) release_object( console->active );
733 console->active = NULL;
735 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
737 if (curr->input == console) curr->input = NULL;
740 free_async_queue( &console->ioctl_q );
741 free_async_queue( &console->read_q );
742 if (console->fd)
743 release_object( console->fd );
746 static struct object *create_console_connection( struct console *console )
748 struct console_connection *connection;
750 if (current->process->console)
752 set_error( STATUS_ACCESS_DENIED );
753 return NULL;
756 if (!(connection = alloc_object( &console_connection_ops ))) return NULL;
757 if (!(connection->fd = alloc_pseudo_fd( &console_connection_fd_ops, &connection->obj, 0 )))
759 release_object( connection );
760 return NULL;
763 if (console)
764 current->process->console = (struct console *)grab_object( console );
766 return &connection->obj;
769 static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
770 unsigned int attr, struct object *root )
772 struct console *console = (struct console *)obj;
773 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
774 assert( obj->ops == &console_ops );
776 if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
778 name->len = 0;
779 return create_console_connection( console );
782 return NULL;
785 static struct object *console_open_file( struct object *obj, unsigned int access,
786 unsigned int sharing, unsigned int options )
788 return grab_object( obj );
791 static void screen_buffer_dump( struct object *obj, int verbose )
793 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
794 assert( obj->ops == &screen_buffer_ops );
796 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
799 static void screen_buffer_destroy( struct object *obj )
801 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
803 assert( obj->ops == &screen_buffer_ops );
805 list_remove( &screen_buffer->entry );
806 if (screen_buffer->input && screen_buffer->input->server)
807 queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_CLOSE_OUTPUT,
808 screen_buffer->id, NULL, NULL );
809 if (screen_buffer->fd) release_object( screen_buffer->fd );
810 free_async_queue( &screen_buffer->ioctl_q );
813 static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
814 unsigned int sharing, unsigned int options )
816 return grab_object( obj );
819 static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry )
821 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
822 if (!screen_buffer->input)
824 set_error( STATUS_ACCESS_DENIED );
825 return 0;
827 return console_add_queue( &screen_buffer->input->obj, entry );
830 static struct fd *screen_buffer_get_fd( struct object *obj )
832 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
833 assert( obj->ops == &screen_buffer_ops );
834 if (screen_buffer->fd)
835 return (struct fd*)grab_object( screen_buffer->fd );
836 set_error( STATUS_OBJECT_TYPE_MISMATCH );
837 return NULL;
840 static void console_server_dump( struct object *obj, int verbose )
842 assert( obj->ops == &console_server_ops );
843 fprintf( stderr, "Console server\n" );
846 static void console_server_destroy( struct object *obj )
848 struct console_server *server = (struct console_server *)obj;
849 assert( obj->ops == &console_server_ops );
850 disconnect_console_server( server );
851 if (server->fd) release_object( server->fd );
854 static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
855 unsigned int attr, struct object *root )
857 struct console_server *server = (struct console_server*)obj;
858 static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
859 assert( obj->ops == &console_server_ops );
861 if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
863 struct screen_buffer *screen_buffer;
864 name->len = 0;
865 if (server->console)
867 set_error( STATUS_INVALID_HANDLE );
868 return 0;
870 if (!(server->console = (struct console *)create_console())) return NULL;
871 if (!(screen_buffer = (struct screen_buffer *)create_screen_buffer( server->console )))
873 release_object( server->console );
874 server->console = NULL;
875 return NULL;
877 release_object( screen_buffer );
878 server->console->server = server;
880 return &server->console->obj;
883 return NULL;
886 static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry )
888 struct console_server *server = (struct console_server*)obj;
889 assert( obj->ops == &console_server_ops );
890 return !server->console || !list_empty( &server->queue );
893 static struct fd *console_server_get_fd( struct object* obj )
895 struct console_server *server = (struct console_server*)obj;
896 assert( obj->ops == &console_server_ops );
897 return (struct fd *)grab_object( server->fd );
900 static struct object *console_server_open_file( struct object *obj, unsigned int access,
901 unsigned int sharing, unsigned int options )
903 return grab_object( obj );
906 static struct object *create_console_server( void )
908 struct console_server *server;
910 if (!(server = alloc_object( &console_server_ops ))) return NULL;
911 server->console = NULL;
912 server->busy = 0;
913 server->once_input = 0;
914 server->term_fd = -1;
915 list_init( &server->queue );
916 list_init( &server->read_queue );
917 server->fd = alloc_pseudo_fd( &console_server_fd_ops, &server->obj, FILE_SYNCHRONOUS_IO_NONALERT );
918 if (!server->fd)
920 release_object( server );
921 return NULL;
923 allow_fd_caching(server->fd);
925 return &server->obj;
928 static int is_blocking_read_ioctl( unsigned int code )
930 switch (code)
932 case IOCTL_CONDRV_READ_INPUT:
933 case IOCTL_CONDRV_READ_CONSOLE:
934 case IOCTL_CONDRV_READ_FILE:
935 return 1;
936 default:
937 return 0;
941 static void console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
943 struct console *console = get_fd_user( fd );
945 switch (code)
947 case IOCTL_CONDRV_CTRL_EVENT:
949 const struct condrv_ctrl_event *event = get_req_data();
950 process_id_t group;
951 if (get_req_data_size() != sizeof(*event))
953 set_error( STATUS_INVALID_PARAMETER );
954 return;
956 group = event->group_id ? event->group_id : current->process->group_id;
957 if (!group)
959 set_error( STATUS_INVALID_PARAMETER );
960 return;
962 propagate_console_signal( console, event->event, group );
963 return;
966 default:
967 if (!console->server || code >> 16 != FILE_DEVICE_CONSOLE)
969 set_error( STATUS_INVALID_HANDLE );
970 return;
972 queue_host_ioctl( console->server, code, 0, async, &console->ioctl_q );
976 static void console_read( struct fd *fd, struct async *async, file_pos_t pos )
978 struct console *console = get_fd_user( fd );
980 if (!console->server)
982 set_error( STATUS_INVALID_HANDLE );
983 return;
985 queue_host_ioctl( console->server, IOCTL_CONDRV_READ_FILE, 0, async, &console->ioctl_q );
988 static void console_flush( struct fd *fd, struct async *async )
990 struct console *console = get_fd_user( fd );
992 if (!console->server)
994 set_error( STATUS_INVALID_HANDLE );
995 return;
997 queue_host_ioctl( console->server, IOCTL_CONDRV_FLUSH, 0, NULL, NULL );
1000 static void screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos )
1002 struct screen_buffer *screen_buffer = get_fd_user( fd );
1004 if (!screen_buffer->input || !screen_buffer->input->server)
1006 set_error( STATUS_INVALID_HANDLE );
1007 return;
1010 queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_WRITE_FILE,
1011 screen_buffer->id, async, &screen_buffer->ioctl_q );
1014 static void screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1016 struct screen_buffer *screen_buffer = get_fd_user( fd );
1018 switch (code)
1020 case IOCTL_CONDRV_ACTIVATE:
1021 if (!screen_buffer->input)
1023 set_error( STATUS_INVALID_HANDLE );
1024 return;
1027 set_active_screen_buffer( screen_buffer->input, screen_buffer );
1028 return;
1030 default:
1031 if (!screen_buffer->input || !screen_buffer->input->server || code >> 16 != FILE_DEVICE_CONSOLE ||
1032 is_blocking_read_ioctl( code ))
1034 set_error( STATUS_INVALID_HANDLE );
1035 return;
1037 queue_host_ioctl( screen_buffer->input->server, code, screen_buffer->id,
1038 async, &screen_buffer->ioctl_q );
1042 static void console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1044 struct console_connection *console_connection = get_fd_user( fd );
1046 switch (code)
1048 case IOCTL_CONDRV_BIND_PID:
1050 struct process *process;
1051 unsigned int pid;
1052 if (get_req_data_size() != sizeof(unsigned int))
1054 set_error( STATUS_INVALID_PARAMETER );
1055 return;
1057 if (current->process->console)
1059 set_error( STATUS_INVALID_HANDLE );
1060 return;
1063 pid = *(unsigned int *)get_req_data();
1064 if (pid == ATTACH_PARENT_PROCESS) pid = current->process->parent_id;
1065 if (!(process = get_process_from_id( pid ))) return;
1067 if (process->console)
1068 current->process->console = (struct console *)grab_object( process->console );
1069 else set_error( STATUS_ACCESS_DENIED );
1070 release_object( process );
1071 return;
1074 default:
1075 default_fd_ioctl( console_connection->fd, code, async );
1079 static void console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1081 struct console_server *server = get_fd_user( fd );
1083 switch (code)
1085 case IOCTL_CONDRV_CTRL_EVENT:
1087 const struct condrv_ctrl_event *event = get_req_data();
1088 if (get_req_data_size() != sizeof(*event))
1090 set_error( STATUS_INVALID_PARAMETER );
1091 return;
1093 if (!server->console)
1095 set_error( STATUS_INVALID_HANDLE );
1096 return;
1098 propagate_console_signal( server->console, event->event, event->group_id );
1099 return;
1102 case IOCTL_CONDRV_SETUP_INPUT:
1104 struct termios term;
1105 obj_handle_t handle;
1106 struct file *file;
1107 int unix_fd;
1109 if (get_req_data_size() != sizeof(unsigned int) || get_reply_max_size())
1111 set_error( STATUS_INVALID_PARAMETER );
1112 return;
1114 if (server->term_fd != -1)
1116 tcsetattr( server->term_fd, TCSANOW, &server->termios );
1117 close( server->term_fd );
1118 server->term_fd = -1;
1120 handle = *(unsigned int *)get_req_data();
1121 if (!handle) return;
1122 if (!(file = get_file_obj( current->process, handle, FILE_READ_DATA )))
1124 return;
1126 unix_fd = get_file_unix_fd( file );
1127 release_object( file );
1129 if (tcgetattr( unix_fd, &server->termios ))
1131 file_set_error();
1132 return;
1134 term = server->termios;
1135 term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
1136 term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
1137 term.c_cflag &= ~(CSIZE | PARENB);
1138 term.c_cflag |= CS8;
1139 term.c_cc[VMIN] = 1;
1140 term.c_cc[VTIME] = 0;
1141 if (tcsetattr( unix_fd, TCSANOW, &term ) || (server->term_fd = dup( unix_fd )) == -1)
1142 file_set_error();
1143 return;
1146 default:
1147 set_error( STATUS_INVALID_HANDLE );
1148 return;
1152 static void console_connection_dump( struct object *obj, int verbose )
1154 fputs( "console connection\n", stderr );
1157 static struct fd *console_connection_get_fd( struct object *obj )
1159 struct console_connection *connection = (struct console_connection *)obj;
1160 return (struct fd *)grab_object( connection->fd );
1163 static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
1164 unsigned int attr, struct object *root )
1166 static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
1168 if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
1170 if (!current->process->console)
1172 set_error( STATUS_INVALID_HANDLE );
1173 return NULL;
1175 name->len = 0;
1176 return grab_object( current->process->console );
1179 return NULL;
1182 static struct object *console_connection_open_file( struct object *obj, unsigned int access,
1183 unsigned int sharing, unsigned int options )
1185 return grab_object( obj );
1188 static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
1190 struct console *console = process->console;
1192 if (console)
1194 process->console = NULL;
1195 release_object( console );
1197 return 1;
1200 static void console_connection_destroy( struct object *obj )
1202 struct console_connection *connection = (struct console_connection *)obj;
1203 if (connection->fd) release_object( connection->fd );
1206 static void console_device_dump( struct object *obj, int verbose )
1208 fputs( "Console device\n", stderr );
1211 static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
1212 unsigned int attr, struct object *root )
1214 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
1215 static const WCHAR consoleW[] = {'C','o','n','s','o','l','e'};
1216 static const WCHAR current_inW[] = {'C','u','r','r','e','n','t','I','n'};
1217 static const WCHAR current_outW[] = {'C','u','r','r','e','n','t','O','u','t'};
1218 static const WCHAR inputW[] = {'I','n','p','u','t'};
1219 static const WCHAR outputW[] = {'O','u','t','p','u','t'};
1220 static const WCHAR screen_bufferW[] = {'S','c','r','e','e','n','B','u','f','f','e','r'};
1221 static const WCHAR serverW[] = {'S','e','r','v','e','r'};
1223 if (name->len == sizeof(current_inW) && !memcmp( name->str, current_inW, name->len ))
1225 if (!current->process->console)
1227 set_error( STATUS_INVALID_HANDLE );
1228 return NULL;
1230 name->len = 0;
1231 return grab_object( current->process->console );
1234 if (name->len == sizeof(current_outW) && !memcmp( name->str, current_outW, name->len ))
1236 if (!current->process->console || !current->process->console->active)
1238 set_error( STATUS_INVALID_HANDLE );
1239 return NULL;
1241 name->len = 0;
1242 return grab_object( current->process->console->active );
1245 if (name->len == sizeof(consoleW) && !memcmp( name->str, consoleW, name->len ))
1247 name->len = 0;
1248 return grab_object( obj );
1251 if (name->len == sizeof(inputW) && !memcmp( name->str, inputW, name->len ))
1253 struct console_input *console_input;
1254 name->len = 0;
1255 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
1256 console_input->fd = alloc_pseudo_fd( &console_input_fd_ops, &console_input->obj,
1257 FILE_SYNCHRONOUS_IO_NONALERT );
1258 if (!console_input->fd)
1260 release_object( console_input );
1261 return NULL;
1263 return &console_input->obj;
1266 if (name->len == sizeof(outputW) && !memcmp( name->str, outputW, name->len ))
1268 struct console_output *console_output;
1269 name->len = 0;
1270 if (!(console_output = alloc_object( &console_output_ops ))) return NULL;
1271 console_output->fd = alloc_pseudo_fd( &console_output_fd_ops, &console_output->obj,
1272 FILE_SYNCHRONOUS_IO_NONALERT );
1273 if (!console_output->fd)
1275 release_object( console_output );
1276 return NULL;
1278 return &console_output->obj;
1281 if (name->len == sizeof(screen_bufferW) && !memcmp( name->str, screen_bufferW, name->len ))
1283 if (!current->process->console)
1285 set_error( STATUS_INVALID_HANDLE );
1286 return NULL;
1288 name->len = 0;
1289 return create_screen_buffer( current->process->console );
1292 if (name->len == sizeof(serverW) && !memcmp( name->str, serverW, name->len ))
1294 name->len = 0;
1295 return create_console_server();
1298 if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
1300 name->len = 0;
1301 return create_console_connection( NULL );
1304 return NULL;
1307 static struct object *console_device_open_file( struct object *obj, unsigned int access,
1308 unsigned int sharing, unsigned int options )
1310 int is_output;
1311 access = default_map_access( obj, access );
1312 is_output = access & FILE_WRITE_DATA;
1313 if (!current->process->console || (is_output && !current->process->console))
1315 set_error( STATUS_INVALID_HANDLE );
1316 return NULL;
1318 if (is_output && (access & FILE_READ_DATA))
1320 set_error( STATUS_INVALID_PARAMETER );
1321 return NULL;
1323 return is_output ? grab_object( current->process->console->active ) : grab_object( current->process->console );
1326 static void console_input_dump( struct object *obj, int verbose )
1328 fputs( "console Input device\n", stderr );
1331 static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry )
1333 if (!current->process->console)
1335 set_error( STATUS_ACCESS_DENIED );
1336 return 0;
1338 return console_add_queue( &current->process->console->obj, entry );
1341 static struct fd *console_input_get_fd( struct object *obj )
1343 struct console_input *console_input = (struct console_input *)obj;
1344 assert( obj->ops == &console_input_ops );
1345 return (struct fd *)grab_object( console_input->fd );
1348 static struct object *console_input_open_file( struct object *obj, unsigned int access,
1349 unsigned int sharing, unsigned int options )
1351 return grab_object( obj );
1354 static void console_input_destroy( struct object *obj )
1356 struct console_input *console_input = (struct console_input *)obj;
1358 assert( obj->ops == &console_input_ops );
1359 if (console_input->fd) release_object( console_input->fd );
1362 static void console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1364 struct console *console = current->process->console;
1366 if (!console)
1368 set_error( STATUS_INVALID_HANDLE );
1369 return;
1371 console_ioctl( console->fd, code, async );
1374 static void console_input_read( struct fd *fd, struct async *async, file_pos_t pos )
1376 struct console *console = current->process->console;
1378 if (!console)
1380 set_error( STATUS_INVALID_HANDLE );
1381 return;
1383 console_read( console->fd, async, pos );
1386 static void console_input_flush( struct fd *fd, struct async *async )
1388 struct console *console = current->process->console;
1390 if (!console)
1392 set_error( STATUS_INVALID_HANDLE );
1393 return;
1395 console_flush( console->fd, async );
1398 static void console_output_dump( struct object *obj, int verbose )
1400 fputs( "console Output device\n", stderr );
1403 static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry )
1405 if (!current->process->console || !current->process->console->active)
1407 set_error( STATUS_ACCESS_DENIED );
1408 return 0;
1410 return console_add_queue( &current->process->console->obj, entry );
1413 static struct fd *console_output_get_fd( struct object *obj )
1415 struct console_output *console_output = (struct console_output *)obj;
1416 assert( obj->ops == &console_output_ops );
1417 return (struct fd *)grab_object( console_output->fd );
1420 static struct object *console_output_open_file( struct object *obj, unsigned int access,
1421 unsigned int sharing, unsigned int options )
1423 return grab_object( obj );
1426 static void console_output_destroy( struct object *obj )
1428 struct console_output *console_output = (struct console_output *)obj;
1430 assert( obj->ops == &console_output_ops );
1431 if (console_output->fd) release_object( console_output->fd );
1434 static void console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1436 struct console *console = current->process->console;
1438 if (!console || !console->active)
1440 set_error( STATUS_INVALID_HANDLE );
1441 return;
1443 screen_buffer_ioctl( console->active->fd, code, async );
1446 static void console_output_write( struct fd *fd, struct async *async, file_pos_t pos )
1448 struct console *console = current->process->console;
1450 if (!console || !console->active)
1452 set_error( STATUS_INVALID_HANDLE );
1453 return;
1455 screen_buffer_write( console->active->fd, async, pos );
1458 struct object *create_console_device( struct object *root, const struct unicode_str *name,
1459 unsigned int attr, const struct security_descriptor *sd )
1461 return create_named_object( root, &console_device_ops, name, attr, sd );
1464 /* retrieve the next pending console ioctl request */
1465 DECL_HANDLER(get_next_console_request)
1467 struct console_host_ioctl *ioctl = NULL, *next;
1468 struct console_server *server;
1469 struct iosb *iosb = NULL;
1471 server = (struct console_server *)get_handle_obj( current->process, req->handle, 0, &console_server_ops );
1472 if (!server) return;
1474 if (!server->console)
1476 set_error( STATUS_INVALID_HANDLE );
1477 release_object( server );
1478 return;
1481 if (!server->console->renderer) server->console->renderer = current;
1483 if (!req->signal) server->console->signaled = 0;
1484 else if (!server->console->signaled)
1486 server->console->signaled = 1;
1487 wake_up( &server->console->obj, 0 );
1490 if (req->read)
1492 /* set result of current pending ioctl */
1493 if (list_empty( &server->read_queue ))
1495 set_error( STATUS_INVALID_HANDLE );
1496 release_object( server );
1497 return;
1500 ioctl = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
1501 list_remove( &ioctl->entry );
1502 list_move_tail( &server->queue, &server->read_queue );
1504 else if (server->busy)
1506 /* set result of previous ioctl */
1507 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1508 list_remove( &ioctl->entry );
1511 if (ioctl)
1513 struct async *async = ioctl->async;
1514 unsigned int status = req->status;
1516 if (status == STATUS_PENDING) status = STATUS_INVALID_PARAMETER;
1517 if (async)
1519 iosb = async_get_iosb( async );
1520 if (iosb->status == STATUS_PENDING)
1522 data_size_t out_size = min( iosb->out_size, get_req_data_size() );
1523 data_size_t result = ioctl->code == IOCTL_CONDRV_WRITE_FILE ? iosb->in_size : out_size;
1524 async_request_complete_alloc( async, status, result, out_size, get_req_data() );
1527 release_object( async );
1529 free( ioctl );
1530 if (iosb) release_object( iosb );
1532 if (req->read)
1534 release_object( server );
1535 return;
1537 server->busy = 0;
1540 /* if we have a blocking read ioctl in queue head and previous blocking read is still waiting,
1541 * move it to read queue for execution after current read is complete. move all blocking
1542 * ioctl at the same time to preserve their order. */
1543 if (!list_empty( &server->queue ) && !list_empty( &server->read_queue ))
1545 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1546 if (is_blocking_read_ioctl( ioctl->code ))
1548 LIST_FOR_EACH_ENTRY_SAFE( ioctl, next, &server->queue, struct console_host_ioctl, entry )
1550 if (!is_blocking_read_ioctl( ioctl->code )) continue;
1551 list_remove( &ioctl->entry );
1552 list_add_tail( &server->read_queue, &ioctl->entry );
1557 /* return the next ioctl */
1558 if (!list_empty( &server->queue ))
1560 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1561 iosb = ioctl->async ? async_get_iosb( ioctl->async ) : NULL;
1563 if (!iosb || get_reply_max_size() >= iosb->in_size)
1565 reply->code = ioctl->code;
1566 reply->output = ioctl->output;
1568 if (iosb)
1570 reply->out_size = iosb->out_size;
1571 set_reply_data_ptr( iosb->in_data, iosb->in_size );
1572 iosb->in_data = NULL;
1575 if (is_blocking_read_ioctl( ioctl->code ))
1577 list_remove( &ioctl->entry );
1578 assert( list_empty( &server->read_queue ));
1579 list_add_tail( &server->read_queue, &ioctl->entry );
1581 else server->busy = 1;
1583 else
1585 reply->out_size = iosb->in_size;
1586 set_error( STATUS_BUFFER_OVERFLOW );
1588 if (iosb) release_object( iosb );
1590 else
1592 set_error( STATUS_PENDING );
1595 release_object( server );