update for HEAD-2003091401
[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 /**********************************************************************
25  * NAME                                                 EXPORTED
26  *      NtSetInformationObject
27  *      
28  * DESCRIPTION
29  *
30  * ARGUMENTS
31  *
32  * RETURN VALUE
33  *
34  * REVISIONS
35  */
36 NTSTATUS STDCALL
37 NtSetInformationObject (IN HANDLE ObjectHandle,
38                         IN CINT ObjectInformationClass,
39                         IN PVOID ObjectInformation,
40                         IN ULONG Length)
41 {
42   UNIMPLEMENTED;
43 }
44
45
46 /*Very, very, very new implementation. Test it!
47
48   Probably we should add meaning to QueryName in POBJECT_TYPE, no matter if we know
49   the correct parameters or not. For FILE_OBJECTs, it would probably look like the code
50   for ObjectNameInformation below. You give it a POBJECT and a PUNICODE_STRING, and it
51   returns the full path in the PUNICODE_STRING
52
53   If we don't do it this way, we should anyway add switches and separate functions to handle
54   the different object types*/
55
56 /**********************************************************************
57  * NAME                                                 EXPORTED
58  *      NtQueryObject
59  *      
60  * DESCRIPTION
61  *
62  * ARGUMENTS
63  *
64  * RETURN VALUE
65  *
66  * REVISIONS
67  */
68 NTSTATUS STDCALL
69 NtQueryObject (IN HANDLE ObjectHandle,
70                IN CINT ObjectInformationClass,
71                OUT PVOID ObjectInformation,
72                IN ULONG Length,
73                OUT PULONG ReturnLength)
74 {
75   POBJECT_TYPE_INFORMATION typeinfo;
76   POBJECT_HEADER ObjectHeader;
77   PVOID Object;
78   NTSTATUS Status;
79
80   Status = ObReferenceObjectByHandle (ObjectHandle,
81                                       0,
82                                       NULL,
83                                       KeGetPreviousMode(),
84                                       &Object,
85                                       NULL);
86   if (!NT_SUCCESS (Status))
87     {
88       return Status;
89     }
90
91   ObjectHeader = BODY_TO_HEADER(Object);
92
93   switch (ObjectInformationClass)
94     {
95       case ObjectNameInformation:
96         Status = ObQueryNameString (Object,
97                                     (POBJECT_NAME_INFORMATION)ObjectInformation,
98                                     Length,
99                                     ReturnLength);
100         break;
101
102       case ObjectTypeInformation:
103         typeinfo = (POBJECT_TYPE_INFORMATION)ObjectInformation;
104         if (Length!=sizeof(OBJECT_TYPE_INFORMATION))
105           return STATUS_INVALID_BUFFER_SIZE;
106
107         // FIXME: Is this supposed to only be the header's Name field?
108         // Can somebody check/verify this?
109         RtlCopyUnicodeString(&typeinfo->Name,&ObjectHeader->Name);
110
111         if (Status != STATUS_SUCCESS)
112           {
113             break;
114           }
115
116         RtlCopyUnicodeString(&typeinfo->Type,&ObjectHeader->ObjectType->TypeName);
117         //This should be info from the object header, not the object type, right?
118         typeinfo->TotalHandles = ObjectHeader-> HandleCount;
119         typeinfo->ReferenceCount = ObjectHeader -> RefCount;
120         break;
121
122       default:
123         Status = STATUS_NOT_IMPLEMENTED;
124         break;
125     }
126
127   ObDereferenceObject(Object);
128
129   return Status;
130 }
131
132
133 /**********************************************************************
134  * NAME                                                 EXPORTED
135  *      ObMakeTemporaryObject
136  *      
137  * DESCRIPTION
138  *
139  * ARGUMENTS
140  *
141  * RETURN VALUE
142  *
143  * REVISIONS
144  *
145  * @implemented
146  */
147 VOID STDCALL
148 ObMakeTemporaryObject (IN PVOID ObjectBody)
149 {
150   POBJECT_HEADER ObjectHeader;
151
152   ObjectHeader = BODY_TO_HEADER(ObjectBody);
153   ObjectHeader->Permanent = FALSE;
154 }
155
156
157 /**********************************************************************
158  * NAME                                                 EXPORTED
159  *      NtMakeTemporaryObject
160  *      
161  * DESCRIPTION
162  *
163  * ARGUMENTS
164  *
165  * RETURN VALUE
166  *
167  * REVISIONS
168  */
169 NTSTATUS
170 STDCALL
171 NtMakeTemporaryObject (IN HANDLE Handle)
172 {
173   POBJECT_HEADER ObjectHeader;
174   PVOID Object;
175   NTSTATUS Status;
176
177   Status = ObReferenceObjectByHandle(Handle,
178                                      0,
179                                      NULL,
180                                      KernelMode,
181                                      & Object,
182                                      NULL);
183   if (Status != STATUS_SUCCESS)
184     {
185       return Status;
186     }
187
188   ObjectHeader = BODY_TO_HEADER(Object);
189   ObjectHeader->Permanent = FALSE;
190
191   ObDereferenceObject(Object);
192
193   return STATUS_SUCCESS;
194 }
195
196 /* EOF */