server: Implement device object.

Vitaliy Margolen wine-patch at kievinfo.com
Mon Dec 5 18:18:30 CST 2005


ChangeLog:
server: Implement device object.

 server/Makefile.in  |    1 
 server/device.c     |  122 +++++++++++++++++++++++++++++++++++++++++++++++++++
 server/protocol.def |   30 +++++++++++++
 3 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 server/device.c
-------------- next part --------------
886389be262c98e6d7df1cb77af6e87b4bf9ffc5
diff --git a/server/Makefile.in b/server/Makefile.in
index ee4a15a..86462eb 100644
--- a/server/Makefile.in
+++ b/server/Makefile.in
@@ -17,6 +17,7 @@ C_SRCS = \
 	context_sparc.c \
 	context_x86_64.c \
 	debugger.c \
+	device.c \
 	directory.c \
 	event.c \
 	fd.c \
diff --git a/server/device.c b/server/device.c
new file mode 100644
index 0000000..5bb7a90
--- /dev/null
+++ b/server/device.c
@@ -0,0 +1,122 @@
+/*
+ * Server-side device object management
+ *
+ * Copyright (C) 2005 Vitaliy Margolen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include <assert.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "winternl.h"
+
+#include "handle.h"
+#include "request.h"
+#include "object.h"
+#include "unicode.h"
+
+struct device
+{
+    struct object obj;            /* object header */
+    obj_handle_t kernel_handle;   /* handle we give to ntoskrnl */
+};
+
+static void device_dump( struct object *obj, int verbose );
+static const struct object_ops device_ops =
+{
+    sizeof(struct device),        /* size */
+    device_dump,                  /* dump */
+    no_add_queue,                 /* add_queue */
+    NULL,                         /* remove_queue */
+    NULL,                         /* signaled */
+    NULL,                         /* satisfied */
+    no_signal,                    /* signal */
+    no_get_fd,                    /* get_fd */
+    no_lookup_name,               /* lookup_name */
+    no_close_handle,              /* close_handle */
+    no_destroy                    /* destroy */
+};
+
+static void device_dump( struct object *obj, int verbose )
+{
+    struct device *device = (struct device *)obj;
+    assert( obj->ops == &device_ops );
+    fprintf( stderr, "Device " );
+    dump_object_name( obj );
+    if (verbose)
+    {
+        fprintf( stderr, " kernel_handle=%p", device->kernel_handle );
+    }
+    fputc( '\n', stderr );
+}
+
+DECL_HANDLER(create_device)
+{
+    struct device *dev;
+    struct unicode_str name;
+
+    get_req_unicode_str( &name );
+    if ((dev = create_named_object_dir( NULL, &name, req->attributes, &device_ops )))
+    {
+        reply->handle = alloc_handle( current->process, dev, 0, 0 );
+
+        if (get_error() != STATUS_OBJECT_NAME_EXISTS)
+            dev->kernel_handle = reply->handle;
+
+        release_object( dev );
+    }
+}
+
+DECL_HANDLER(open_device)
+{
+    struct unicode_str name;
+    struct directory *root = NULL;
+    struct device *dev;
+
+    get_req_unicode_str( &name );
+    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
+        return;
+
+    if ((dev = open_object_dir( root, &name, req->attributes, NULL )))
+    {
+        reply->handle = alloc_handle( current->process, &dev->obj, req->access,
+                                      req->attributes & OBJ_INHERIT );
+        release_object( dev );
+    }
+
+    if (root) release_object( root );
+}
+
+DECL_HANDLER(query_device)
+{
+    struct device *dev;
+    dev = (struct device *)get_handle_obj( current->process, req->handle, 0, &device_ops );
+    
+    if (!dev) return;
+
+    reply->kernel_handle = dev->kernel_handle;
+
+    release_object( dev );
+}
diff --git a/server/protocol.def b/server/protocol.def
index dc302b0..496cec2 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -2573,3 +2573,33 @@ enum message_type
 @REPLY
     VARARG(target_name,unicode_str); /* target name */
 @END
+
+
+/* Create device object */
+ at REQ(create_device)
+    unsigned int   attributes;    /* object attributes */
+    void*          device_object; /* pointer to DEVICE_OBJECT */
+    VARARG(device_name,unicode_str); /* Device name */
+ at REPLY
+    obj_handle_t   handle;        /* handle to the symlink */
+ at END
+
+
+/* Open device object */
+ at REQ(open_device)
+    unsigned int   access;        /* access flags */
+    unsigned int   attributes;    /* object attributes */
+    obj_handle_t   rootdir;       /* root directory */
+    VARARG(device_name,unicode_str); /* Device name */
+ at REPLY
+    obj_handle_t   handle;        /* handle to the symlink */
+ at END
+
+
+/* Query a device object */
+ at REQ(query_device)
+    obj_handle_t   handle;        /* handle to the device */
+ at REPLY
+    obj_handle_t   kernel_handle; /* ntoskrnl handle for the device */
+ at END
+


More information about the wine-patches mailing list