ReactOS  0.4.13-dev-73-gcfe54aa
devicemap.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/ob/devicemap.c
5  * PURPOSE: Device map implementation
6  * PROGRAMMERS: Eric Kohl (eric.kohl@reactos.org)
7  * Alex Ionescu (alex.ionescu@reactos.org)
8  */
9 
10 /* INCLUDES ***************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* PRIVATE FUNCTIONS ******************************************************/
17 
19 NTAPI
21 {
22  POBJECT_DIRECTORY DirectoryObject = NULL;
23  PDEVICE_MAP DeviceMap = NULL;
25 
30  (PVOID*)&DirectoryObject,
31  NULL);
32  if (!NT_SUCCESS(Status))
33  {
34  DPRINT("ObReferenceObjectByHandle() failed (Status 0x%08lx)\n", Status);
35  return Status;
36  }
37 
38  /* Allocate and initialize a new device map */
40  sizeof(*DeviceMap),
41  'mDbO');
42  if (DeviceMap == NULL)
43  {
44  ObDereferenceObject(DirectoryObject);
46  }
47 
48  /* Initialize the device map */
49  RtlZeroMemory(DeviceMap, sizeof(*DeviceMap));
50  DeviceMap->ReferenceCount = 1;
51  DeviceMap->DosDevicesDirectory = DirectoryObject;
52 
53  /* Acquire the device map lock */
55 
56  /* Attach the device map to the directory object */
57  DirectoryObject->DeviceMap = DeviceMap;
58 
59  /* Attach the device map to the process */
60  ObSystemDeviceMap = DeviceMap;
61  PsGetCurrentProcess()->DeviceMap = DeviceMap;
62 
63  /* Release the device map lock */
65 
66  return STATUS_SUCCESS;
67 }
68 
69 
70 VOID
71 NTAPI
73 {
74  PDEVICE_MAP DeviceMap;
75 
76  DPRINT("ObDereferenceDeviceMap()\n");
77 
78  /* Get the pointer to this process devicemap and reset it
79  holding the device map lock */
81  DeviceMap = Process->DeviceMap;
82  Process->DeviceMap = NULL;
84 
85  /* Continue only if there is a device map */
86  if (DeviceMap == NULL)
87  return;
88 
89  /* Acquire the device map lock again */
91 
92  /* Decrement the reference counter */
93  DeviceMap->ReferenceCount--;
94  DPRINT("ReferenceCount: %lu\n", DeviceMap->ReferenceCount);
95 
96  /* Leave, if there are still references to this device map */
97  if (DeviceMap->ReferenceCount != 0)
98  {
99  /* Release the device map lock and leave */
101  return;
102  }
103 
104  /* Nobody is referencing it anymore, unlink the DOS directory */
105  DeviceMap->DosDevicesDirectory->DeviceMap = NULL;
106 
107  /* Release the device map lock */
109 
110  /* Dereference the DOS Devices Directory and free the DeviceMap */
112  ExFreePoolWithTag(DeviceMap, 'mDbO');
113 }
114 
115 
116 VOID
117 FASTCALL
119 {
120  DPRINT("ObfDereferenceDeviceMap()\n");
121 
122  /* Acquire the device map lock */
124 
125  /* Decrement the reference counter */
126  DeviceMap->ReferenceCount--;
127  DPRINT("ReferenceCount: %lu\n", DeviceMap->ReferenceCount);
128 
129  /* Leave, if there are still references to this device map */
130  if (DeviceMap->ReferenceCount != 0)
131  {
132  /* Release the device map lock and leave */
134  return;
135  }
136 
137  /* Nobody is referencing it anymore, unlink the DOS directory */
138  DeviceMap->DosDevicesDirectory->DeviceMap = NULL;
139 
140  /* Release the devicemap lock */
142 
143  /* Dereference the DOS Devices Directory and free the Device Map */
144  ObDereferenceObject(DeviceMap->DosDevicesDirectory );
145  ExFreePoolWithTag(DeviceMap, 'mDbO');
146 }
147 
148 
149 VOID
150 NTAPI
153 {
154  PDEVICE_MAP DeviceMap;
155 
156  DPRINT("ObInheritDeviceMap()\n");
157 
158  /* Acquire the device map lock */
160 
161  /* Get the parent process device map or the system device map */
162  DeviceMap = (Parent != NULL) ? Parent->DeviceMap : ObSystemDeviceMap;
163  if (DeviceMap != NULL)
164  {
165  /* Reference the device map and attach it to the new process */
166  DeviceMap->ReferenceCount++;
167  DPRINT("ReferenceCount: %lu\n", DeviceMap->ReferenceCount);
168 
169  Process->DeviceMap = DeviceMap;
170  }
171 
172  /* Release the device map lock */
174 }
175 
176 
177 VOID
178 NTAPI
180  IN PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo)
181 {
182  PDEVICE_MAP DeviceMap;
183 
184  /* Acquire the device map lock */
186 
187  /* Get the process device map or the system device map */
188  DeviceMap = (Process != NULL) ? Process->DeviceMap : ObSystemDeviceMap;
189  if (DeviceMap != NULL)
190  {
191  /* Make a copy */
192  DeviceMapInfo->Query.DriveMap = DeviceMap->DriveMap;
193  RtlCopyMemory(DeviceMapInfo->Query.DriveType,
194  DeviceMap->DriveType,
195  sizeof(DeviceMap->DriveType));
196  }
197 
198  /* Release the device map lock */
200 }
201 
202 
203 #if 0
204 NTSTATUS
205 NTAPI
206 ObIsDosDeviceLocallyMapped(
207  IN ULONG Index,
208  OUT PUCHAR DosDeviceState)
209 {
210  /* Check the index */
211  if (Index < 1 || Index > 26)
213 
214  /* Acquire the device map lock */
216 
217  /* Get drive mapping status */
218  *DosDeviceState = (ObSystemDeviceMap->DriveMap & (1 << Index)) != 0;
219 
220  /* Release the device map lock */
222 
223  return STATUS_SUCCESS;
224 }
225 #endif
226 
227 /* EOF */
#define IN
Definition: typedefs.h:38
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
#define KeGetPreviousMode()
Definition: ketypes.h:1081
LONG NTSTATUS
Definition: precomp.h:26
static HANDLE DirectoryHandle
Definition: ObType.c:48
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:716
#define FASTCALL
Definition: nt_native.h:50
ULONG DriveMap
Definition: obtypes.h:528
VOID NTAPI ObDereferenceDeviceMap(IN PEPROCESS Process)
Definition: devicemap.c:72
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID FASTCALL ObfDereferenceDeviceMap(IN PDEVICE_MAP DeviceMap)
Definition: devicemap.c:118
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
#define ObpDirectoryObjectType
Definition: ObTypes.c:123
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
VOID NTAPI ObQueryDeviceMapInformation(IN PEPROCESS Process, IN PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo)
Definition: devicemap.c:179
UCHAR DriveType[32]
Definition: obtypes.h:529
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDEVICE_MAP ObSystemDeviceMap
Definition: obinit.c:46
Status
Definition: gdiplustypes.h:24
struct _DEVICE_MAP * DeviceMap
Definition: obtypes.h:418
ULONG ReferenceCount
Definition: obtypes.h:527
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI ObpCreateDeviceMap(IN HANDLE DirectoryHandle)
Definition: devicemap.c:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
POBJECT_DIRECTORY DosDevicesDirectory
Definition: obtypes.h:525
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
KGUARDED_MUTEX ObpDeviceMapLock
Definition: oblife.c:24
return STATUS_SUCCESS
Definition: btrfs.c:2725
VOID NTAPI ObInheritDeviceMap(IN PEPROCESS Parent, IN PEPROCESS Process)
Definition: devicemap.c:151