Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. devobj.c
  5. Abstract:
  6. This module contains code which implements the DEVICE_CONTEXT object.
  7. The device context object is a structure which contains a
  8. system-defined DEVICE_OBJECT followed by information which is maintained
  9. by the provider, called the context.
  10. Author:
  11. Colin Watson (ColinW) 13-Mar-1991
  12. Environment:
  13. Kernel mode
  14. Revision History:
  15. --*/
  16. #include "nb.h"
  17. #ifdef ALLOC_PRAGMA
  18. #pragma alloc_text(INIT, NbCreateDeviceContext)
  19. #endif
  20. NTSTATUS
  21. NbCreateDeviceContext(
  22. IN PDRIVER_OBJECT DriverObject,
  23. IN PUNICODE_STRING DeviceName,
  24. IN OUT PDEVICE_CONTEXT *DeviceContext,
  25. IN PUNICODE_STRING RegistryPath
  26. )
  27. /*++
  28. Routine Description:
  29. This routine creates and initializes a device context structure.
  30. Arguments:
  31. DriverObject - pointer to the IO subsystem supplied driver object.
  32. DeviceContext - Pointer to a pointer to a transport device context object.
  33. DeviceName - pointer to the name of the device this device object points to.
  34. RegistryPath - The name of the Netbios node in the registry.
  35. Return Value:
  36. STATUS_SUCCESS if all is well; STATUS_INSUFFICIENT_RESOURCES otherwise.
  37. --*/
  38. {
  39. NTSTATUS status;
  40. PDEVICE_OBJECT deviceObject;
  41. PDEVICE_CONTEXT deviceContext;
  42. PAGED_CODE();
  43. //
  44. // Create the device object for NETBEUI.
  45. //
  46. status = IoCreateDevice(
  47. DriverObject,
  48. sizeof (DEVICE_CONTEXT) + RegistryPath->Length - sizeof (DEVICE_OBJECT),
  49. DeviceName,
  50. FILE_DEVICE_TRANSPORT,
  51. FILE_DEVICE_SECURE_OPEN,
  52. FALSE,
  53. &deviceObject);
  54. if (!NT_SUCCESS(status)) {
  55. return status;
  56. }
  57. // DeviceContext contains:
  58. // the device object
  59. // Intialized
  60. // RegistryPath
  61. deviceContext = (PDEVICE_CONTEXT)deviceObject;
  62. deviceObject->Flags |= DO_DIRECT_IO;
  63. //
  64. // Determine the IRP stack size that we should "export".
  65. //
  66. deviceObject->StackSize = GetIrpStackSize(
  67. RegistryPath,
  68. NB_DEFAULT_IO_STACKSIZE);
  69. deviceContext->RegistryPath.MaximumLength = RegistryPath->Length;
  70. deviceContext->RegistryPath.Buffer = (PWSTR)(deviceContext+1);
  71. RtlCopyUnicodeString( &deviceContext->RegistryPath, RegistryPath );
  72. //
  73. // Initialize the driver object with this driver's entry points.
  74. //
  75. DriverObject->MajorFunction [IRP_MJ_CREATE] = NbDispatch;
  76. DriverObject->MajorFunction [IRP_MJ_CLOSE] = NbDispatch;
  77. DriverObject->MajorFunction [IRP_MJ_CLEANUP] = NbDispatch;
  78. DriverObject->MajorFunction [IRP_MJ_DEVICE_CONTROL] = NbDispatch;
  79. DriverObject-> DriverUnload = NbDriverUnload;
  80. *DeviceContext = deviceContext;
  81. return STATUS_SUCCESS;
  82. }