cryptdlg: Use wide-char string literals.
[wine.git] / server / console.c
bloba2171b3c1b4e6bccd1b7f9572a520d8f0904422d
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"
25 #include "wine/port.h"
27 #include <assert.h>
28 #include <string.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <signal.h>
32 #include <sys/ioctl.h>
33 #include <termios.h>
35 #include "ntstatus.h"
36 #define WIN32_NO_STATUS
37 #include "handle.h"
38 #include "process.h"
39 #include "request.h"
40 #include "file.h"
41 #include "unicode.h"
42 #include "wincon.h"
43 #include "winternl.h"
44 #include "wine/condrv.h"
46 struct screen_buffer;
48 struct history_line
50 data_size_t len;
51 WCHAR text[1];
54 struct console
56 struct object obj; /* object header */
57 int signaled; /* is console signaled */
58 struct thread *renderer; /* console renderer thread */
59 struct screen_buffer *active; /* active screen buffer */
60 struct console_server *server; /* console server object */
61 unsigned int last_id; /* id of last created console buffer */
62 struct fd *fd; /* for bare console, attached input fd */
63 struct async_queue ioctl_q; /* ioctl queue */
64 struct async_queue read_q; /* read queue */
67 static void console_dump( struct object *obj, int verbose );
68 static void console_destroy( struct object *obj );
69 static int console_signaled( struct object *obj, struct wait_queue_entry *entry );
70 static struct fd *console_get_fd( struct object *obj );
71 static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
72 unsigned int attr, struct object *root );
73 static struct object *console_open_file( struct object *obj, unsigned int access,
74 unsigned int sharing, unsigned int options );
76 static const struct object_ops console_ops =
78 sizeof(struct console), /* size */
79 console_dump, /* dump */
80 no_get_type, /* get_type */
81 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_fd_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, unsigned int info_class );
103 static int console_read( struct fd *fd, struct async *async, file_pos_t pos );
104 static int console_flush( struct fd *fd, struct async *async );
105 static int 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_queue_async, /* queue_async */
119 default_fd_reselect_async /* reselect_async */
122 struct console_host_ioctl
124 unsigned int code; /* ioctl code */
125 int output; /* output id for screen buffer ioctls */
126 struct async *async; /* ioctl async */
127 struct list entry; /* list entry */
130 struct console_server
132 struct object obj; /* object header */
133 struct fd *fd; /* pseudo-fd for ioctls */
134 struct console *console; /* attached console */
135 struct list queue; /* ioctl queue */
136 struct list read_queue; /* blocking read queue */
137 int busy; /* flag if server processing an ioctl */
138 int term_fd; /* UNIX terminal fd */
139 struct termios termios; /* original termios */
142 static void console_server_dump( struct object *obj, int verbose );
143 static void console_server_destroy( struct object *obj );
144 static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry );
145 static struct fd *console_server_get_fd( struct object *obj );
146 static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
147 unsigned int attr, struct object *root );
148 static struct object *console_server_open_file( struct object *obj, unsigned int access,
149 unsigned int sharing, unsigned int options );
151 static const struct object_ops console_server_ops =
153 sizeof(struct console_server), /* size */
154 console_server_dump, /* dump */
155 no_get_type, /* get_type */
156 add_queue, /* add_queue */
157 remove_queue, /* remove_queue */
158 console_server_signaled, /* signaled */
159 no_satisfied, /* satisfied */
160 no_signal, /* signal */
161 console_server_get_fd, /* get_fd */
162 default_fd_map_access, /* map_access */
163 default_get_sd, /* get_sd */
164 default_set_sd, /* set_sd */
165 no_get_full_name, /* get_full_name */
166 console_server_lookup_name, /* lookup_name */
167 no_link_name, /* link_name */
168 NULL, /* unlink_name */
169 console_server_open_file, /* open_file */
170 no_kernel_obj_list, /* get_kernel_obj_list */
171 fd_close_handle, /* close_handle */
172 console_server_destroy /* destroy */
175 static int console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
177 static const struct fd_ops console_server_fd_ops =
179 default_fd_get_poll_events, /* get_poll_events */
180 default_poll_event, /* poll_event */
181 console_get_fd_type, /* get_fd_type */
182 no_fd_read, /* read */
183 no_fd_write, /* write */
184 no_fd_flush, /* flush */
185 no_fd_get_file_info, /* get_file_info */
186 no_fd_get_volume_info, /* get_volume_info */
187 console_server_ioctl, /* ioctl */
188 default_fd_queue_async, /* queue_async */
189 default_fd_reselect_async /* reselect_async */
192 struct font_info
194 short int width;
195 short int height;
196 short int weight;
197 short int pitch_family;
198 WCHAR *face_name;
199 data_size_t face_len;
202 struct screen_buffer
204 struct object obj; /* object header */
205 struct list entry; /* entry in list of all screen buffers */
206 struct console *input; /* associated console input */
207 unsigned int id; /* buffer id */
208 struct fd *fd; /* for bare console, attached output fd */
209 struct async_queue ioctl_q; /* ioctl queue */
212 static void screen_buffer_dump( struct object *obj, int verbose );
213 static void screen_buffer_destroy( struct object *obj );
214 static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry );
215 static struct fd *screen_buffer_get_fd( struct object *obj );
216 static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
217 unsigned int sharing, unsigned int options );
219 static const struct object_ops screen_buffer_ops =
221 sizeof(struct screen_buffer), /* size */
222 screen_buffer_dump, /* dump */
223 no_get_type, /* get_type */
224 screen_buffer_add_queue, /* add_queue */
225 NULL, /* remove_queue */
226 NULL, /* signaled */
227 NULL, /* satisfied */
228 no_signal, /* signal */
229 screen_buffer_get_fd, /* get_fd */
230 default_fd_map_access, /* map_access */
231 default_get_sd, /* get_sd */
232 default_set_sd, /* set_sd */
233 no_get_full_name, /* get_full_name */
234 no_lookup_name, /* lookup_name */
235 no_link_name, /* link_name */
236 NULL, /* unlink_name */
237 screen_buffer_open_file, /* open_file */
238 no_kernel_obj_list, /* get_kernel_obj_list */
239 no_close_handle, /* close_handle */
240 screen_buffer_destroy /* destroy */
243 static int screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos );
244 static int screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
246 static const struct fd_ops screen_buffer_fd_ops =
248 default_fd_get_poll_events, /* get_poll_events */
249 default_poll_event, /* poll_event */
250 console_get_fd_type, /* get_fd_type */
251 no_fd_read, /* read */
252 screen_buffer_write, /* write */
253 no_fd_flush, /* flush */
254 console_get_file_info, /* get_file_info */
255 console_get_volume_info, /* get_volume_info */
256 screen_buffer_ioctl, /* ioctl */
257 default_fd_queue_async, /* queue_async */
258 default_fd_reselect_async /* reselect_async */
261 static struct object_type *console_device_get_type( struct object *obj );
262 static void console_device_dump( struct object *obj, int verbose );
263 static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
264 unsigned int attr, struct object *root );
265 static struct object *console_device_open_file( struct object *obj, unsigned int access,
266 unsigned int sharing, unsigned int options );
268 static const struct object_ops console_device_ops =
270 sizeof(struct object), /* size */
271 console_device_dump, /* dump */
272 console_device_get_type, /* get_type */
273 no_add_queue, /* add_queue */
274 NULL, /* remove_queue */
275 NULL, /* signaled */
276 no_satisfied, /* satisfied */
277 no_signal, /* signal */
278 no_get_fd, /* get_fd */
279 default_fd_map_access, /* map_access */
280 default_get_sd, /* get_sd */
281 default_set_sd, /* set_sd */
282 default_get_full_name, /* get_full_name */
283 console_device_lookup_name, /* lookup_name */
284 directory_link_name, /* link_name */
285 default_unlink_name, /* unlink_name */
286 console_device_open_file, /* open_file */
287 no_kernel_obj_list, /* get_kernel_obj_list */
288 no_close_handle, /* close_handle */
289 no_destroy /* destroy */
292 struct console_input
294 struct object obj; /* object header */
295 struct fd *fd; /* pseudo-fd */
298 static void console_input_dump( struct object *obj, int verbose );
299 static struct object *console_input_open_file( struct object *obj, unsigned int access,
300 unsigned int sharing, unsigned int options );
301 static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry );
302 static struct fd *console_input_get_fd( struct object *obj );
303 static void console_input_destroy( struct object *obj );
305 static const struct object_ops console_input_ops =
307 sizeof(struct console_input), /* size */
308 console_input_dump, /* dump */
309 console_device_get_type, /* get_type */
310 console_input_add_queue, /* add_queue */
311 NULL, /* remove_queue */
312 NULL, /* signaled */
313 no_satisfied, /* satisfied */
314 no_signal, /* signal */
315 console_input_get_fd, /* get_fd */
316 no_map_access, /* map_access */
317 default_get_sd, /* get_sd */
318 default_set_sd, /* set_sd */
319 no_get_full_name, /* get_full_name */
320 no_lookup_name, /* lookup_name */
321 directory_link_name, /* link_name */
322 default_unlink_name, /* unlink_name */
323 console_input_open_file, /* open_file */
324 no_kernel_obj_list, /* get_kernel_obj_list */
325 no_close_handle, /* close_handle */
326 console_input_destroy /* destroy */
329 static int console_input_read( struct fd *fd, struct async *async, file_pos_t pos );
330 static int console_input_flush( struct fd *fd, struct async *async );
331 static int console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
333 static const struct fd_ops console_input_fd_ops =
335 default_fd_get_poll_events, /* get_poll_events */
336 default_poll_event, /* poll_event */
337 console_get_fd_type, /* get_fd_type */
338 console_input_read, /* read */
339 no_fd_write, /* write */
340 console_input_flush, /* flush */
341 console_get_file_info, /* get_file_info */
342 console_get_volume_info, /* get_volume_info */
343 console_input_ioctl, /* ioctl */
344 default_fd_queue_async, /* queue_async */
345 default_fd_reselect_async /* reselect_async */
348 struct console_output
350 struct object obj; /* object header */
351 struct fd *fd; /* pseudo-fd */
354 static void console_output_dump( struct object *obj, int verbose );
355 static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry );
356 static struct fd *console_output_get_fd( struct object *obj );
357 static struct object *console_output_open_file( struct object *obj, unsigned int access,
358 unsigned int sharing, unsigned int options );
359 static void console_output_destroy( struct object *obj );
361 static const struct object_ops console_output_ops =
363 sizeof(struct console_output), /* size */
364 console_output_dump, /* dump */
365 console_device_get_type, /* get_type */
366 console_output_add_queue, /* add_queue */
367 NULL, /* remove_queue */
368 NULL, /* signaled */
369 no_satisfied, /* satisfied */
370 no_signal, /* signal */
371 console_output_get_fd, /* get_fd */
372 no_map_access, /* map_access */
373 default_get_sd, /* get_sd */
374 default_set_sd, /* set_sd */
375 no_get_full_name, /* get_full_name */
376 no_lookup_name, /* lookup_name */
377 directory_link_name, /* link_name */
378 default_unlink_name, /* unlink_name */
379 console_output_open_file, /* open_file */
380 no_kernel_obj_list, /* get_kernel_obj_list */
381 no_close_handle, /* close_handle */
382 console_output_destroy /* destroy */
385 static int console_output_write( struct fd *fd, struct async *async, file_pos_t pos );
386 static int console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
388 static const struct fd_ops console_output_fd_ops =
390 default_fd_get_poll_events, /* get_poll_events */
391 default_poll_event, /* poll_event */
392 console_get_fd_type, /* get_fd_type */
393 no_fd_read, /* read */
394 console_output_write, /* write */
395 no_fd_flush, /* flush */
396 console_get_file_info, /* get_file_info */
397 console_get_volume_info, /* get_volume_info */
398 console_output_ioctl, /* ioctl */
399 default_fd_queue_async, /* queue_async */
400 default_fd_reselect_async /* reselect_async */
403 struct console_connection
405 struct object obj; /* object header */
406 struct fd *fd; /* pseudo-fd for ioctls */
409 static void console_connection_dump( struct object *obj, int verbose );
410 static struct fd *console_connection_get_fd( struct object *obj );
411 static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
412 unsigned int attr, struct object *root );
413 static struct object *console_connection_open_file( struct object *obj, unsigned int access,
414 unsigned int sharing, unsigned int options );
415 static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
416 static void console_connection_destroy( struct object *obj );
418 static const struct object_ops console_connection_ops =
420 sizeof(struct console_connection),/* size */
421 console_connection_dump, /* dump */
422 console_device_get_type, /* get_type */
423 no_add_queue, /* add_queue */
424 NULL, /* remove_queue */
425 NULL, /* signaled */
426 no_satisfied, /* satisfied */
427 no_signal, /* signal */
428 console_connection_get_fd, /* get_fd */
429 no_map_access, /* map_access */
430 default_get_sd, /* get_sd */
431 default_set_sd, /* set_sd */
432 no_get_full_name, /* get_full_name */
433 console_connection_lookup_name, /* lookup_name */
434 directory_link_name, /* link_name */
435 default_unlink_name, /* unlink_name */
436 console_connection_open_file, /* open_file */
437 no_kernel_obj_list, /* get_kernel_obj_list */
438 console_connection_close_handle, /* close_handle */
439 console_connection_destroy /* destroy */
442 static int console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
444 static const struct fd_ops console_connection_fd_ops =
446 default_fd_get_poll_events, /* get_poll_events */
447 default_poll_event, /* poll_event */
448 console_get_fd_type, /* get_fd_type */
449 no_fd_read, /* read */
450 no_fd_write, /* write */
451 no_fd_flush, /* flush */
452 no_fd_get_file_info, /* get_file_info */
453 no_fd_get_volume_info, /* get_volume_info */
454 console_connection_ioctl, /* ioctl */
455 default_fd_queue_async, /* queue_async */
456 default_fd_reselect_async /* reselect_async */
459 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
461 static int console_signaled( struct object *obj, struct wait_queue_entry *entry )
463 struct console *console = (struct console*)obj;
464 return console->signaled;
467 static struct fd *console_get_fd( struct object *obj )
469 struct console *console = (struct console *)obj;
470 assert( obj->ops == &console_ops );
471 return (struct fd *)grab_object( console->fd );
474 static enum server_fd_type console_get_fd_type( struct fd *fd )
476 return FD_TYPE_CHAR;
479 static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
481 set_error( STATUS_INVALID_DEVICE_REQUEST );
484 static void console_get_volume_info( struct fd *fd, unsigned int info_class )
486 switch (info_class)
488 case FileFsDeviceInformation:
490 static const FILE_FS_DEVICE_INFORMATION device_info =
492 FILE_DEVICE_CONSOLE,
493 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
495 if (get_reply_max_size() >= sizeof(device_info))
496 set_reply_data( &device_info, sizeof(device_info) );
497 else
498 set_error( STATUS_BUFFER_TOO_SMALL );
499 break;
501 default:
502 set_error( STATUS_NOT_IMPLEMENTED );
506 static struct object *create_console(void)
508 struct console *console;
510 if (!(console = alloc_object( &console_ops )))
511 return NULL;
513 console->renderer = NULL;
514 console->signaled = 0;
515 console->active = NULL;
516 console->server = NULL;
517 console->fd = NULL;
518 console->last_id = 0;
519 init_async_queue( &console->ioctl_q );
520 init_async_queue( &console->read_q );
522 console->fd = alloc_pseudo_fd( &console_fd_ops, &console->obj, FILE_SYNCHRONOUS_IO_NONALERT );
523 if (!console->fd)
525 release_object( console );
526 return NULL;
528 allow_fd_caching( console->fd );
529 return &console->obj;
532 static void console_host_ioctl_terminate( struct console_host_ioctl *call, unsigned int status )
534 if (call->async)
536 async_terminate( call->async, status );
537 release_object( call->async );
539 free( call );
542 static int queue_host_ioctl( struct console_server *server, unsigned int code, unsigned int output,
543 struct async *async, struct async_queue *queue )
545 struct console_host_ioctl *ioctl;
547 if (!(ioctl = mem_alloc( sizeof(*ioctl) ))) return 0;
548 ioctl->code = code;
549 ioctl->output = output;
550 ioctl->async = NULL;
551 if (async)
553 ioctl->async = (struct async *)grab_object( async );
554 queue_async( queue, async );
556 list_add_tail( &server->queue, &ioctl->entry );
557 wake_up( &server->obj, 0 );
558 if (async) set_error( STATUS_PENDING );
559 return 1;
562 static void disconnect_console_server( struct console_server *server )
564 while (!list_empty( &server->queue ))
566 struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
567 list_remove( &call->entry );
568 console_host_ioctl_terminate( call, STATUS_CANCELLED );
570 while (!list_empty( &server->read_queue ))
572 struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
573 list_remove( &call->entry );
574 console_host_ioctl_terminate( call, STATUS_CANCELLED );
577 if (server->term_fd != -1)
579 tcsetattr( server->term_fd, TCSANOW, &server->termios );
580 close( server->term_fd );
581 server->term_fd = -1;
584 if (server->console)
586 assert( server->console->server == server );
587 server->console->server = NULL;
588 server->console = NULL;
589 wake_up( &server->obj, 0 );
593 static void set_active_screen_buffer( struct console *console, struct screen_buffer *screen_buffer )
595 if (console->active == screen_buffer) return;
596 if (console->active) release_object( console->active );
597 console->active = (struct screen_buffer *)grab_object( screen_buffer );
599 if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_ACTIVATE,
600 screen_buffer->id, NULL, NULL );
603 static struct object *create_screen_buffer( struct console *console )
605 struct screen_buffer *screen_buffer;
607 if (console->last_id == ~0)
609 set_error( STATUS_NO_MEMORY );
610 return NULL;
613 if (!(screen_buffer = alloc_object( &screen_buffer_ops )))
614 return NULL;
616 screen_buffer->id = ++console->last_id;
617 screen_buffer->input = console;
618 init_async_queue( &screen_buffer->ioctl_q );
619 list_add_head( &screen_buffer_list, &screen_buffer->entry );
621 screen_buffer->fd = alloc_pseudo_fd( &screen_buffer_fd_ops, &screen_buffer->obj,
622 FILE_SYNCHRONOUS_IO_NONALERT );
623 if (!screen_buffer->fd)
625 release_object( screen_buffer );
626 return NULL;
628 allow_fd_caching(screen_buffer->fd);
630 if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_INIT_OUTPUT,
631 screen_buffer->id, NULL, NULL );
632 if (!console->active) set_active_screen_buffer( console, screen_buffer );
633 return &screen_buffer->obj;
636 struct thread *console_get_renderer( struct console *console )
638 return console->renderer;
641 struct console_signal_info
643 struct console *console;
644 process_id_t group;
645 int signal;
648 static int propagate_console_signal_cb(struct process *process, void *user)
650 struct console_signal_info* csi = (struct console_signal_info*)user;
652 if (process->console == csi->console && process->running_threads &&
653 (!csi->group || process->group_id == csi->group))
655 /* find a suitable thread to signal */
656 struct thread *thread;
657 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
659 if (send_thread_signal( thread, csi->signal )) break;
662 return FALSE;
665 static void propagate_console_signal( struct console *console,
666 int sig, process_id_t group_id )
668 struct console_signal_info csi;
670 if (!console)
672 set_error( STATUS_INVALID_PARAMETER );
673 return;
675 /* FIXME: should support the other events (like CTRL_BREAK) */
676 if (sig != CTRL_C_EVENT)
678 set_error( STATUS_NOT_IMPLEMENTED );
679 return;
681 csi.console = console;
682 csi.signal = SIGINT;
683 csi.group = group_id;
685 enum_processes(propagate_console_signal_cb, &csi);
688 /* dumb dump */
689 static void console_dump( struct object *obj, int verbose )
691 struct console *console = (struct console *)obj;
692 assert( obj->ops == &console_ops );
693 fprintf( stderr, "Console input active=%p server=%p\n",
694 console->active, console->server );
697 static void console_destroy( struct object *obj )
699 struct console *console = (struct console *)obj;
700 struct screen_buffer *curr;
702 assert( obj->ops == &console_ops );
704 if (console->server)
706 assert( console->server->console == console );
707 disconnect_console_server( console->server );
710 if (console->active) release_object( console->active );
711 console->active = NULL;
713 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
715 if (curr->input == console) curr->input = NULL;
718 free_async_queue( &console->ioctl_q );
719 free_async_queue( &console->read_q );
720 if (console->fd)
721 release_object( console->fd );
724 static struct object *create_console_connection( struct console *console )
726 struct console_connection *connection;
728 if (current->process->console)
730 set_error( STATUS_ACCESS_DENIED );
731 return NULL;
734 if (!(connection = alloc_object( &console_connection_ops ))) return NULL;
735 if (!(connection->fd = alloc_pseudo_fd( &console_connection_fd_ops, &connection->obj, 0 )))
737 release_object( connection );
738 return NULL;
741 if (console)
742 current->process->console = (struct console *)grab_object( console );
744 return &connection->obj;
747 static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
748 unsigned int attr, struct object *root )
750 struct console *console = (struct console *)obj;
751 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
752 assert( obj->ops == &console_ops );
754 if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
756 name->len = 0;
757 return create_console_connection( console );
760 return NULL;
763 static struct object *console_open_file( struct object *obj, unsigned int access,
764 unsigned int sharing, unsigned int options )
766 return grab_object( obj );
769 static void screen_buffer_dump( struct object *obj, int verbose )
771 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
772 assert( obj->ops == &screen_buffer_ops );
774 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
777 static void screen_buffer_destroy( struct object *obj )
779 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
781 assert( obj->ops == &screen_buffer_ops );
783 list_remove( &screen_buffer->entry );
784 if (screen_buffer->input && screen_buffer->input->server)
785 queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_CLOSE_OUTPUT,
786 screen_buffer->id, NULL, NULL );
787 if (screen_buffer->fd) release_object( screen_buffer->fd );
788 free_async_queue( &screen_buffer->ioctl_q );
791 static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
792 unsigned int sharing, unsigned int options )
794 return grab_object( obj );
797 static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry )
799 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
800 if (!screen_buffer->input)
802 set_error( STATUS_ACCESS_DENIED );
803 return 0;
805 return add_queue( &screen_buffer->input->obj, entry );
808 static struct fd *screen_buffer_get_fd( struct object *obj )
810 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
811 assert( obj->ops == &screen_buffer_ops );
812 if (screen_buffer->fd)
813 return (struct fd*)grab_object( screen_buffer->fd );
814 set_error( STATUS_OBJECT_TYPE_MISMATCH );
815 return NULL;
818 static void console_server_dump( struct object *obj, int verbose )
820 assert( obj->ops == &console_server_ops );
821 fprintf( stderr, "Console server\n" );
824 static void console_server_destroy( struct object *obj )
826 struct console_server *server = (struct console_server *)obj;
827 assert( obj->ops == &console_server_ops );
828 disconnect_console_server( server );
829 if (server->fd) release_object( server->fd );
832 static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
833 unsigned int attr, struct object *root )
835 struct console_server *server = (struct console_server*)obj;
836 static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
837 assert( obj->ops == &console_server_ops );
839 if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
841 struct screen_buffer *screen_buffer;
842 name->len = 0;
843 if (server->console)
845 set_error( STATUS_INVALID_HANDLE );
846 return 0;
848 if (!(server->console = (struct console *)create_console())) return NULL;
849 if (!(screen_buffer = (struct screen_buffer *)create_screen_buffer( server->console )))
851 release_object( server->console );
852 server->console = NULL;
853 return NULL;
855 release_object( screen_buffer );
856 server->console->server = server;
858 return &server->console->obj;
861 return NULL;
864 static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry )
866 struct console_server *server = (struct console_server*)obj;
867 assert( obj->ops == &console_server_ops );
868 return !server->console || !list_empty( &server->queue );
871 static struct fd *console_server_get_fd( struct object* obj )
873 struct console_server *server = (struct console_server*)obj;
874 assert( obj->ops == &console_server_ops );
875 return (struct fd *)grab_object( server->fd );
878 static struct object *console_server_open_file( struct object *obj, unsigned int access,
879 unsigned int sharing, unsigned int options )
881 return grab_object( obj );
884 static struct object *create_console_server( void )
886 struct console_server *server;
888 if (!(server = alloc_object( &console_server_ops ))) return NULL;
889 server->console = NULL;
890 server->busy = 0;
891 server->term_fd = -1;
892 list_init( &server->queue );
893 list_init( &server->read_queue );
894 server->fd = alloc_pseudo_fd( &console_server_fd_ops, &server->obj, FILE_SYNCHRONOUS_IO_NONALERT );
895 if (!server->fd)
897 release_object( server );
898 return NULL;
900 allow_fd_caching(server->fd);
902 return &server->obj;
905 static int is_blocking_read_ioctl( unsigned int code )
907 switch (code)
909 case IOCTL_CONDRV_READ_INPUT:
910 case IOCTL_CONDRV_READ_CONSOLE:
911 case IOCTL_CONDRV_READ_FILE:
912 return 1;
913 default:
914 return 0;
918 static int console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
920 struct console *console = get_fd_user( fd );
922 switch (code)
924 case IOCTL_CONDRV_CTRL_EVENT:
926 const struct condrv_ctrl_event *event = get_req_data();
927 process_id_t group;
928 if (get_req_data_size() != sizeof(*event))
930 set_error( STATUS_INVALID_PARAMETER );
931 return 0;
933 group = event->group_id ? event->group_id : current->process->group_id;
934 if (!group)
936 set_error( STATUS_INVALID_PARAMETER );
937 return 0;
939 propagate_console_signal( console, event->event, group );
940 return !get_error();
943 default:
944 if (!console->server || code >> 16 != FILE_DEVICE_CONSOLE)
946 set_error( STATUS_INVALID_HANDLE );
947 return 0;
949 return queue_host_ioctl( console->server, code, 0, async, &console->ioctl_q );
953 static int console_read( struct fd *fd, struct async *async, file_pos_t pos )
955 struct console *console = get_fd_user( fd );
957 if (!console->server)
959 set_error( STATUS_INVALID_HANDLE );
960 return 0;
962 return queue_host_ioctl( console->server, IOCTL_CONDRV_READ_FILE, 0, async, &console->ioctl_q );
965 static int console_flush( struct fd *fd, struct async *async )
967 struct console *console = get_fd_user( fd );
969 if (!console->server)
971 set_error( STATUS_INVALID_HANDLE );
972 return 0;
974 return queue_host_ioctl( console->server, IOCTL_CONDRV_FLUSH, 0, NULL, NULL );
977 static int screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos )
979 struct screen_buffer *screen_buffer = get_fd_user( fd );
980 struct iosb *iosb;
982 if (!screen_buffer->input || !screen_buffer->input->server)
984 set_error( STATUS_INVALID_HANDLE );
985 return 0;
988 if (!queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_WRITE_FILE,
989 screen_buffer->id, async, &screen_buffer->ioctl_q ))
990 return 0;
992 /* we can't use default async handling, because write result is not
993 * compatible with ioctl result */
994 iosb = async_get_iosb( async );
995 iosb->status = STATUS_SUCCESS;
996 iosb->result = iosb->in_size;
997 async_terminate( async, iosb->result ? STATUS_ALERTED : STATUS_SUCCESS );
998 release_object( iosb );
999 return 1;
1002 static int screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1004 struct screen_buffer *screen_buffer = get_fd_user( fd );
1006 switch (code)
1008 case IOCTL_CONDRV_ACTIVATE:
1009 if (!screen_buffer->input)
1011 set_error( STATUS_INVALID_HANDLE );
1012 return 0;
1015 set_active_screen_buffer( screen_buffer->input, screen_buffer );
1016 return 1;
1018 default:
1019 if (!screen_buffer->input || !screen_buffer->input->server || code >> 16 != FILE_DEVICE_CONSOLE ||
1020 is_blocking_read_ioctl( code ))
1022 set_error( STATUS_INVALID_HANDLE );
1023 return 0;
1025 return queue_host_ioctl( screen_buffer->input->server, code, screen_buffer->id,
1026 async, &screen_buffer->ioctl_q );
1030 static int console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1032 struct console_connection *console_connection = get_fd_user( fd );
1034 switch (code)
1036 case IOCTL_CONDRV_BIND_PID:
1038 struct process *process;
1039 unsigned int pid;
1040 if (get_req_data_size() != sizeof(unsigned int))
1042 set_error( STATUS_INVALID_PARAMETER );
1043 return 0;
1045 if (current->process->console)
1047 set_error( STATUS_INVALID_HANDLE );
1048 return 0;
1051 pid = *(unsigned int *)get_req_data();
1052 if (pid == ATTACH_PARENT_PROCESS) pid = current->process->parent_id;
1053 if (!(process = get_process_from_id( pid ))) return 0;
1055 if (process->console)
1056 current->process->console = (struct console *)grab_object( process->console );
1057 else set_error( STATUS_ACCESS_DENIED );
1058 release_object( process );
1059 return !get_error();
1062 default:
1063 return default_fd_ioctl( console_connection->fd, code, async );
1067 static int console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1069 struct console_server *server = get_fd_user( fd );
1071 switch (code)
1073 case IOCTL_CONDRV_CTRL_EVENT:
1075 const struct condrv_ctrl_event *event = get_req_data();
1076 if (get_req_data_size() != sizeof(*event))
1078 set_error( STATUS_INVALID_PARAMETER );
1079 return 0;
1081 if (!server->console)
1083 set_error( STATUS_INVALID_HANDLE );
1084 return 0;
1086 propagate_console_signal( server->console, event->event, event->group_id );
1087 return !get_error();
1090 case IOCTL_CONDRV_SETUP_INPUT:
1092 struct termios term;
1093 obj_handle_t handle;
1094 struct file *file;
1095 int unix_fd;
1097 if (get_req_data_size() != sizeof(unsigned int) || get_reply_max_size())
1099 set_error( STATUS_INVALID_PARAMETER );
1100 return 0;
1102 if (server->term_fd != -1)
1104 tcsetattr( server->term_fd, TCSANOW, &server->termios );
1105 close( server->term_fd );
1106 server->term_fd = -1;
1108 handle = *(unsigned int *)get_req_data();
1109 if (!handle) return 1;
1110 if (!(file = get_file_obj( current->process, handle, FILE_READ_DATA )))
1112 return 0;
1114 unix_fd = get_file_unix_fd( file );
1115 release_object( file );
1117 if (tcgetattr( unix_fd, &server->termios ))
1119 file_set_error();
1120 return 0;
1122 term = server->termios;
1123 term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
1124 term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
1125 term.c_cflag &= ~(CSIZE | PARENB);
1126 term.c_cflag |= CS8;
1127 term.c_cc[VMIN] = 1;
1128 term.c_cc[VTIME] = 0;
1129 if (tcsetattr( unix_fd, TCSANOW, &term ) || (server->term_fd = dup( unix_fd )) == -1)
1131 file_set_error();
1132 return 0;
1134 return 1;
1137 default:
1138 set_error( STATUS_INVALID_HANDLE );
1139 return 0;
1143 static void console_connection_dump( struct object *obj, int verbose )
1145 fputs( "console connection\n", stderr );
1148 static struct fd *console_connection_get_fd( struct object *obj )
1150 struct console_connection *connection = (struct console_connection *)obj;
1151 return (struct fd *)grab_object( connection->fd );
1154 static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
1155 unsigned int attr, struct object *root )
1157 static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
1159 if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
1161 if (!current->process->console)
1163 set_error( STATUS_INVALID_HANDLE );
1164 return NULL;
1166 name->len = 0;
1167 return grab_object( current->process->console );
1170 return NULL;
1173 static struct object *console_connection_open_file( struct object *obj, unsigned int access,
1174 unsigned int sharing, unsigned int options )
1176 return grab_object( obj );
1179 static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
1181 struct console *console = process->console;
1183 if (console)
1185 process->console = NULL;
1186 release_object( console );
1188 return 1;
1191 static void console_connection_destroy( struct object *obj )
1193 struct console_connection *connection = (struct console_connection *)obj;
1194 if (connection->fd) release_object( connection->fd );
1197 static struct object_type *console_device_get_type( struct object *obj )
1199 static const WCHAR name[] = {'D','e','v','i','c','e'};
1200 static const struct unicode_str str = { name, sizeof(name) };
1201 return get_object_type( &str );
1204 static void console_device_dump( struct object *obj, int verbose )
1206 fputs( "Console device\n", stderr );
1209 static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
1210 unsigned int attr, struct object *root )
1212 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
1213 static const WCHAR consoleW[] = {'C','o','n','s','o','l','e'};
1214 static const WCHAR current_inW[] = {'C','u','r','r','e','n','t','I','n'};
1215 static const WCHAR current_outW[] = {'C','u','r','r','e','n','t','O','u','t'};
1216 static const WCHAR inputW[] = {'I','n','p','u','t'};
1217 static const WCHAR outputW[] = {'O','u','t','p','u','t'};
1218 static const WCHAR screen_bufferW[] = {'S','c','r','e','e','n','B','u','f','f','e','r'};
1219 static const WCHAR serverW[] = {'S','e','r','v','e','r'};
1221 if (name->len == sizeof(current_inW) && !memcmp( name->str, current_inW, name->len ))
1223 if (!current->process->console)
1225 set_error( STATUS_INVALID_HANDLE );
1226 return NULL;
1228 name->len = 0;
1229 return grab_object( current->process->console );
1232 if (name->len == sizeof(current_outW) && !memcmp( name->str, current_outW, name->len ))
1234 if (!current->process->console || !current->process->console->active)
1236 set_error( STATUS_INVALID_HANDLE );
1237 return NULL;
1239 name->len = 0;
1240 return grab_object( current->process->console->active );
1243 if (name->len == sizeof(consoleW) && !memcmp( name->str, consoleW, name->len ))
1245 name->len = 0;
1246 return grab_object( obj );
1249 if (name->len == sizeof(inputW) && !memcmp( name->str, inputW, name->len ))
1251 struct console_input *console_input;
1252 name->len = 0;
1253 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
1254 console_input->fd = alloc_pseudo_fd( &console_input_fd_ops, &console_input->obj,
1255 FILE_SYNCHRONOUS_IO_NONALERT );
1256 if (!console_input->fd)
1258 release_object( console_input );
1259 return NULL;
1261 return &console_input->obj;
1264 if (name->len == sizeof(outputW) && !memcmp( name->str, outputW, name->len ))
1266 struct console_output *console_output;
1267 name->len = 0;
1268 if (!(console_output = alloc_object( &console_output_ops ))) return NULL;
1269 console_output->fd = alloc_pseudo_fd( &console_output_fd_ops, &console_output->obj,
1270 FILE_SYNCHRONOUS_IO_NONALERT );
1271 if (!console_output->fd)
1273 release_object( console_output );
1274 return NULL;
1276 return &console_output->obj;
1279 if (name->len == sizeof(screen_bufferW) && !memcmp( name->str, screen_bufferW, name->len ))
1281 if (!current->process->console)
1283 set_error( STATUS_INVALID_HANDLE );
1284 return NULL;
1286 name->len = 0;
1287 return create_screen_buffer( current->process->console );
1290 if (name->len == sizeof(serverW) && !memcmp( name->str, serverW, name->len ))
1292 name->len = 0;
1293 return create_console_server();
1296 if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
1298 name->len = 0;
1299 return create_console_connection( NULL );
1302 return NULL;
1305 static struct object *console_device_open_file( struct object *obj, unsigned int access,
1306 unsigned int sharing, unsigned int options )
1308 int is_output;
1309 access = default_fd_map_access( obj, access );
1310 is_output = access & FILE_WRITE_DATA;
1311 if (!current->process->console || (is_output && !current->process->console))
1313 set_error( STATUS_INVALID_HANDLE );
1314 return NULL;
1316 if (is_output && (access & FILE_READ_DATA))
1318 set_error( STATUS_INVALID_PARAMETER );
1319 return NULL;
1321 return is_output ? grab_object( current->process->console->active ) : grab_object( current->process->console );
1324 static void console_input_dump( struct object *obj, int verbose )
1326 fputs( "console Input device\n", stderr );
1329 static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry )
1331 if (!current->process->console)
1333 set_error( STATUS_ACCESS_DENIED );
1334 return 0;
1336 return add_queue( &current->process->console->obj, entry );
1339 static struct fd *console_input_get_fd( struct object *obj )
1341 struct console_input *console_input = (struct console_input *)obj;
1342 assert( obj->ops == &console_input_ops );
1343 return (struct fd *)grab_object( console_input->fd );
1346 static struct object *console_input_open_file( struct object *obj, unsigned int access,
1347 unsigned int sharing, unsigned int options )
1349 return grab_object( obj );
1352 static void console_input_destroy( struct object *obj )
1354 struct console_input *console_input = (struct console_input *)obj;
1356 assert( obj->ops == &console_input_ops );
1357 if (console_input->fd) release_object( console_input->fd );
1360 static int console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1362 struct console *console = current->process->console;
1364 if (!console)
1366 set_error( STATUS_INVALID_HANDLE );
1367 return 0;
1369 return console_ioctl( console->fd, code, async );
1372 static int console_input_read( struct fd *fd, struct async *async, file_pos_t pos )
1374 struct console *console = current->process->console;
1376 if (!console)
1378 set_error( STATUS_INVALID_HANDLE );
1379 return 0;
1381 return console_read( console->fd, async, pos );
1384 static int console_input_flush( struct fd *fd, struct async *async )
1386 struct console *console = current->process->console;
1388 if (!console)
1390 set_error( STATUS_INVALID_HANDLE );
1391 return 0;
1393 return console_flush( console->fd, async );
1396 static void console_output_dump( struct object *obj, int verbose )
1398 fputs( "console Output device\n", stderr );
1401 static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry )
1403 if (!current->process->console || !current->process->console->active)
1405 set_error( STATUS_ACCESS_DENIED );
1406 return 0;
1408 return add_queue( &current->process->console->obj, entry );
1411 static struct fd *console_output_get_fd( struct object *obj )
1413 struct console_output *console_output = (struct console_output *)obj;
1414 assert( obj->ops == &console_output_ops );
1415 return (struct fd *)grab_object( console_output->fd );
1418 static struct object *console_output_open_file( struct object *obj, unsigned int access,
1419 unsigned int sharing, unsigned int options )
1421 return grab_object( obj );
1424 static void console_output_destroy( struct object *obj )
1426 struct console_output *console_output = (struct console_output *)obj;
1428 assert( obj->ops == &console_output_ops );
1429 if (console_output->fd) release_object( console_output->fd );
1432 static int console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1434 struct console *console = current->process->console;
1436 if (!console || !console->active)
1438 set_error( STATUS_INVALID_HANDLE );
1439 return 0;
1441 return screen_buffer_ioctl( console->active->fd, code, async );
1444 static int console_output_write( struct fd *fd, struct async *async, file_pos_t pos )
1446 struct console *console = current->process->console;
1448 if (!console || !console->active)
1450 set_error( STATUS_INVALID_HANDLE );
1451 return 0;
1453 return screen_buffer_write( console->active->fd, async, pos );
1456 struct object *create_console_device( struct object *root, const struct unicode_str *name,
1457 unsigned int attr, const struct security_descriptor *sd )
1459 return create_named_object( root, &console_device_ops, name, attr, sd );
1462 /* retrieve the next pending console ioctl request */
1463 DECL_HANDLER(get_next_console_request)
1465 struct console_host_ioctl *ioctl = NULL, *next;
1466 struct console_server *server;
1467 struct iosb *iosb = NULL;
1469 server = (struct console_server *)get_handle_obj( current->process, req->handle, 0, &console_server_ops );
1470 if (!server) return;
1472 if (!server->console)
1474 set_error( STATUS_INVALID_HANDLE );
1475 release_object( server );
1476 return;
1479 if (!server->console->renderer) server->console->renderer = current;
1481 if (!req->signal) server->console->signaled = 0;
1482 else if (!server->console->signaled)
1484 server->console->signaled = 1;
1485 wake_up( &server->console->obj, 0 );
1488 if (req->read)
1490 /* set result of current pending ioctl */
1491 if (list_empty( &server->read_queue ))
1493 set_error( STATUS_INVALID_HANDLE );
1494 release_object( server );
1495 return;
1498 ioctl = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
1499 list_remove( &ioctl->entry );
1500 list_move_tail( &server->queue, &server->read_queue );
1502 else if (server->busy)
1504 /* set result of previous ioctl */
1505 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1506 list_remove( &ioctl->entry );
1509 if (ioctl)
1511 unsigned int status = req->status;
1512 if (status == STATUS_PENDING) status = STATUS_INVALID_PARAMETER;
1513 if (ioctl->async)
1515 iosb = async_get_iosb( ioctl->async );
1516 if (iosb->status == STATUS_PENDING)
1518 iosb->status = status;
1519 iosb->out_size = min( iosb->out_size, get_req_data_size() );
1520 if (iosb->out_size)
1522 if ((iosb->out_data = memdup( get_req_data(), iosb->out_size )))
1524 iosb->result = iosb->out_size;
1525 status = STATUS_ALERTED;
1527 else if (!status)
1529 iosb->status = STATUS_NO_MEMORY;
1530 iosb->out_size = 0;
1534 else
1536 release_object( ioctl->async );
1537 ioctl->async = NULL;
1540 console_host_ioctl_terminate( ioctl, status );
1541 if (iosb) release_object( iosb );
1543 if (req->read)
1545 release_object( server );
1546 return;
1548 server->busy = 0;
1551 /* if we have a blocking read ioctl in queue head and previous blocking read is still waiting,
1552 * move it to read queue for execution after current read is complete. move all blocking
1553 * ioctl at the same time to preserve their order. */
1554 if (!list_empty( &server->queue ) && !list_empty( &server->read_queue ))
1556 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1557 if (is_blocking_read_ioctl( ioctl->code ))
1559 LIST_FOR_EACH_ENTRY_SAFE( ioctl, next, &server->queue, struct console_host_ioctl, entry )
1561 if (!is_blocking_read_ioctl( ioctl->code )) continue;
1562 list_remove( &ioctl->entry );
1563 list_add_tail( &server->read_queue, &ioctl->entry );
1568 /* return the next ioctl */
1569 if (!list_empty( &server->queue ))
1571 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1572 iosb = ioctl->async ? async_get_iosb( ioctl->async ) : NULL;
1574 if (!iosb || get_reply_max_size() >= iosb->in_size)
1576 reply->code = ioctl->code;
1577 reply->output = ioctl->output;
1579 if (iosb)
1581 reply->out_size = iosb->out_size;
1582 set_reply_data_ptr( iosb->in_data, iosb->in_size );
1583 iosb->in_data = NULL;
1586 if (is_blocking_read_ioctl( ioctl->code ))
1588 list_remove( &ioctl->entry );
1589 assert( list_empty( &server->read_queue ));
1590 list_add_tail( &server->read_queue, &ioctl->entry );
1592 else server->busy = 1;
1594 else
1596 reply->out_size = iosb->in_size;
1597 set_error( STATUS_BUFFER_OVERFLOW );
1599 if (iosb) release_object( iosb );
1601 else
1603 set_error( STATUS_PENDING );
1606 release_object( server );