d59b705bfedea118f3f41239fc7714abb656e0a6
[reactos.git] / ntoskrnl / ob / ntobj.c
1 /* $Id$
2  *
3  * COPYRIGHT:     See COPYING in the top level directory
4  * PROJECT:       ReactOS kernel
5  * FILE:          ntoskrnl/ob/ntobj.c
6  * PURPOSE:       User mode interface to object manager
7  * PROGRAMMER:    David Welch (welch@cwcom.net)
8  * UPDATE HISTORY:
9  *               10/06/98: Created
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/ob.h>
16 #include <internal/id.h>
17
18 #define NDEBUG
19 #include <internal/debug.h>
20
21
22 /* FUNCTIONS ************************************************************/
23
24 #ifndef LIBCAPTIVE
25
26 /**********************************************************************
27  * NAME                                                 EXPORTED
28  *      NtSetInformationObject
29  *      
30  * DESCRIPTION
31  *
32  * ARGUMENTS
33  *
34  * RETURN VALUE
35  *
36  * REVISIONS
37  */
38 NTSTATUS STDCALL
39 NtSetInformationObject (IN HANDLE ObjectHandle,
40                         IN CINT ObjectInformationClass,
41                         IN PVOID ObjectInformation,
42                         IN ULONG Length)
43 {
44   UNIMPLEMENTED;
45 }
46
47 #endif /* LIBCAPTIVE */
48
49 NTSTATUS
50 internalNameBuilder
51 (
52 POBJECT_HEADER  ObjectHeader,
53 PUNICODE_STRING string)
54 /* So, what's the purpose of this function?
55    It will take any OBJECT_HEADER and traverse the Parent structure up to the root
56    and form the name, i.e. this will only work on objects where the Parent/Name fields
57    have any meaning (not files) */
58 {
59         NTSTATUS status;
60         if (ObjectHeader->Parent)
61         {
62                 status = internalNameBuilder(BODY_TO_HEADER(ObjectHeader->Parent),string);
63                 if (status != STATUS_SUCCESS)
64                 {
65                         return status;
66                 }
67         }
68         if (ObjectHeader->Name.Buffer)
69         {
70                 status = RtlAppendUnicodeToString(string, REACTOS_UCS2(L"\\"));
71                 if (status != STATUS_SUCCESS) return status;
72                 return RtlAppendUnicodeStringToString(string, &ObjectHeader->Name);
73         }
74         return STATUS_SUCCESS;
75 }
76
77 #ifndef LIBCAPTIVE
78
79 /*Very, very, very new implementation. Test it!
80
81   Probably we should add meaning to QueryName in POBJECT_TYPE, no matter if we know
82   the correct parameters or not. For FILE_OBJECTs, it would probably look like the code
83   for ObjectNameInformation below. You give it a POBJECT and a PUNICODE_STRING, and it
84   returns the full path in the PUNICODE_STRING
85
86   If we don't do it this way, we should anyway add switches and separate functions to handle
87   the different object types*/
88
89 /**********************************************************************
90  * NAME                                                 EXPORTED
91  *      NtQueryObject
92  *      
93  * DESCRIPTION
94  *
95  * ARGUMENTS
96  *
97  * RETURN VALUE
98  *
99  * REVISIONS
100  */
101 NTSTATUS STDCALL
102 NtQueryObject (IN HANDLE ObjectHandle,
103                IN CINT ObjectInformationClass,
104                OUT PVOID ObjectInformation,
105                IN ULONG Length,
106                OUT PULONG ReturnLength)
107 {
108   POBJECT_TYPE_INFORMATION typeinfo;
109   POBJECT_HEADER ObjectHeader;
110   PVOID Object;
111   NTSTATUS Status;
112
113   Status = ObReferenceObjectByHandle (ObjectHandle,
114                                       0,
115                                       NULL,
116                                       KeGetPreviousMode(),
117                                       &Object,
118                                       NULL);
119   if (!NT_SUCCESS (Status))
120     {
121       return Status;
122     }
123
124   ObjectHeader = BODY_TO_HEADER(Object);
125
126   switch (ObjectInformationClass)
127     {
128       case ObjectNameInformation:
129         Status = ObQueryNameString (Object,
130                                     (POBJECT_NAME_INFORMATION)ObjectInformation,
131                                     Length,
132                                     ReturnLength);
133         break;
134
135       case ObjectTypeInformation:
136         typeinfo = (POBJECT_TYPE_INFORMATION)ObjectInformation;
137         if (Length!=sizeof(OBJECT_TYPE_INFORMATION))
138           return STATUS_INVALID_BUFFER_SIZE;
139
140         // FIXME: Is this supposed to only be the header's Name field?
141         // Can somebody check/verify this?
142         RtlCopyUnicodeString(&typeinfo->Name,&ObjectHeader->Name);
143
144         if (Status != STATUS_SUCCESS)
145           {
146             break;
147           }
148
149         RtlCopyUnicodeString(&typeinfo->Type,&ObjectHeader->ObjectType->TypeName);
150         //This should be info from the object header, not the object type, right?
151         typeinfo->TotalHandles = ObjectHeader-> HandleCount;
152         typeinfo->ReferenceCount = ObjectHeader -> RefCount;
153         break;
154
155       default:
156         Status = STATUS_NOT_IMPLEMENTED;
157         break;
158     }
159
160   ObDereferenceObject(Object);
161
162   return Status;
163 }
164
165
166 /**********************************************************************
167  * NAME                                                 EXPORTED
168  *      ObMakeTemporaryObject
169  *      
170  * DESCRIPTION
171  *
172  * ARGUMENTS
173  *
174  * RETURN VALUE
175  *
176  * REVISIONS
177  *
178  * @implemented
179  */
180 VOID STDCALL
181 ObMakeTemporaryObject (IN PVOID ObjectBody)
182 {
183   POBJECT_HEADER ObjectHeader;
184
185   ObjectHeader = BODY_TO_HEADER(ObjectBody);
186   ObjectHeader->Permanent = FALSE;
187 }
188
189
190 /**********************************************************************
191  * NAME                                                 EXPORTED
192  *      NtMakeTemporaryObject
193  *      
194  * DESCRIPTION
195  *
196  * ARGUMENTS
197  *
198  * RETURN VALUE
199  *
200  * REVISIONS
201  */
202 NTSTATUS
203 STDCALL
204 NtMakeTemporaryObject (IN HANDLE Handle)
205 {
206   POBJECT_HEADER ObjectHeader;
207   PVOID Object;
208   NTSTATUS Status;
209
210   Status = ObReferenceObjectByHandle(Handle,
211                                      0,
212                                      NULL,
213                                      KernelMode,
214                                      & Object,
215                                      NULL);
216   if (Status != STATUS_SUCCESS)
217     {
218       return Status;
219     }
220
221   ObjectHeader = BODY_TO_HEADER(Object);
222   ObjectHeader->Permanent = FALSE;
223
224   ObDereferenceObject(Object);
225
226   return STATUS_SUCCESS;
227 }
228
229 #endif /* LIBCAPTIVE */
230
231 /* EOF */