From 5979e58fc6228860e334732dffe5c04332287764 Mon Sep 17 00:00:00 2001
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
Date: Sat, 23 May 2020 21:39:41 -0600
Subject: server: Allow volume information queries to be asynchronous.

Signed-off-by: Erich E. Hoover <erich.e.hoover@gmail.com>
---
 server/console.c    |  5 +++--
 server/fd.c         | 13 +++++++++----
 server/file.h       |  4 ++--
 server/named_pipe.c |  5 +++--
 server/protocol.def |  2 ++
 5 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/server/console.c b/server/console.c
index cd6076f0033..92bda51846c 100644
--- a/server/console.c
+++ b/server/console.c
@@ -99,7 +99,7 @@ static const struct object_ops console_ops =
 
 static enum server_fd_type console_get_fd_type( struct fd *fd );
 static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
-static void console_get_volume_info( struct fd *fd, unsigned int info_class );
+static int console_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class );
 static int console_read( struct fd *fd, struct async *async, file_pos_t pos );
 static int console_flush( struct fd *fd, struct async *async );
 static int console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
@@ -480,7 +480,7 @@ static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned
     set_error( STATUS_INVALID_DEVICE_REQUEST );
 }
 
-static void console_get_volume_info( struct fd *fd, unsigned int info_class )
+static int console_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class )
 {
     switch (info_class)
     {
@@ -500,6 +500,7 @@ static void console_get_volume_info( struct fd *fd, unsigned int info_class )
     default:
         set_error( STATUS_NOT_IMPLEMENTED );
     }
+    return 0;
 }
 
 static struct object *create_console(void)
diff --git a/server/fd.c b/server/fd.c
index 2dcdd04a892..65a6f876e5c 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -2369,9 +2369,10 @@ void default_fd_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int
 }
 
 /* default get_volume_info() routine */
-void no_fd_get_volume_info( struct fd *fd, unsigned int info_class )
+int no_fd_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class )
 {
     set_error( STATUS_OBJECT_TYPE_MISMATCH );
+    return 0;
 }
 
 /* default ioctl() routine */
@@ -2666,12 +2667,16 @@ DECL_HANDLER(get_file_info)
 DECL_HANDLER(get_volume_info)
 {
     struct fd *fd = get_handle_fd_obj( current->process, req->handle, 0 );
+    struct async *async;
 
-    if (fd)
+    if (!fd) return;
+
+    if ((async = create_request_async( fd, fd->comp_flags, &req->async )))
     {
-        fd->fd_ops->get_volume_info( fd, req->info_class );
-        release_object( fd );
+        reply->wait = async_handoff( async, fd->fd_ops->get_volume_info( fd, async, req->info_class ), NULL, 1 );
+        release_object( async );
     }
+    release_object( fd );
 }
 
 /* open a file object */
diff --git a/server/file.h b/server/file.h
index 3b70799a3ec..fbfd1e4eec9 100644
--- a/server/file.h
+++ b/server/file.h
@@ -65,7 +65,7 @@ struct fd_ops
     /* query file info */
     void (*get_file_info)( struct fd *, obj_handle_t, unsigned int );
     /* query volume info */
-    void (*get_volume_info)( struct fd *, unsigned int );
+    int (*get_volume_info)( struct fd *, struct async *, unsigned int );
     /* perform an ioctl on the file */
     int (*ioctl)(struct fd *fd, ioctl_code_t code, struct async *async );
     /* queue an async operation */
@@ -114,7 +114,7 @@ extern int no_fd_write( struct fd *fd, struct async *async, file_pos_t pos );
 extern int no_fd_flush( struct fd *fd, struct async *async );
 extern void no_fd_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
 extern void default_fd_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
-extern void no_fd_get_volume_info( struct fd *fd, unsigned int info_class );
+extern int no_fd_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class );
 extern int no_fd_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
 extern int default_fd_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
 extern void no_fd_queue_async( struct fd *fd, struct async *async, int type, int count );
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 2e80ef3b1aa..a3ce9d463f1 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -146,7 +146,7 @@ static WCHAR *pipe_end_get_full_name( struct object *obj, data_size_t *len );
 static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos );
 static int pipe_end_write( struct fd *fd, struct async *async_data, file_pos_t pos );
 static int pipe_end_flush( struct fd *fd, struct async *async );
-static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class );
+static int pipe_end_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class );
 static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue );
 static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
 
@@ -742,7 +742,7 @@ static WCHAR *pipe_end_get_full_name( struct object *obj, data_size_t *len )
     return pipe_end->pipe->obj.ops->get_full_name( &pipe_end->pipe->obj, len );
 }
 
-static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class )
+static int pipe_end_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class )
 {
     switch (info_class)
     {
@@ -762,6 +762,7 @@ static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class )
     default:
         set_error( STATUS_NOT_IMPLEMENTED );
     }
+    return 0;
 }
 
 static void message_queue_read( struct pipe_end *pipe_end, struct iosb *iosb )
diff --git a/server/protocol.def b/server/protocol.def
index 07ed22c0b64..c1dc6cc84d1 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1405,9 +1405,11 @@ enum server_fd_type
 
 /* Query volume information */
 @REQ(get_volume_info)
+    async_data_t async;         /* async I/O parameters */
     obj_handle_t handle;        /* handle to the file */
     unsigned int info_class;    /* queried information class */
 @REPLY
+    obj_handle_t wait;          /* handle to wait on for blocking read */
     VARARG(data,bytes);         /* volume info data */
 @END
 
-- 
2.17.1

