1 /* $Id: file.c,v 1.13 2001/03/06 23:34:39 cnettel Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/file.c
6 * PURPOSE: Graceful system shutdown if a bug is detected
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/io.h>
18 #include <internal/debug.h>
20 /* FUNCTIONS *****************************************************************/
22 NTSTATUS STDCALL
internalQueryFileInfo (
23 IN PFILE_OBJECT FileObject
,
24 IN FILE_INFORMATION_CLASS FileInformationClass
,
25 PIO_STATUS_BLOCK IoStatusBlock
,
27 OUT PVOID FileInformation
,
28 OUT PULONG ReturnedLength
// FIXME: ReturnedLength not implemented
31 //This code is taken from old NtQueryInformationFile, now shared with IoQueryFileInformation
33 PDEVICE_OBJECT DeviceObject
;
36 PIO_STACK_LOCATION StackPtr
;
39 KeInitializeEvent(&Event
,NotificationEvent
,FALSE
);
40 DeviceObject
= FileObject
->DeviceObject
;
42 Irp
= IoAllocateIrp(DeviceObject
->StackSize
, TRUE
);
45 ObDereferenceObject(FileObject
);
46 return STATUS_UNSUCCESSFUL
;
49 Irp
->UserIosb
= IoStatusBlock
;
50 Irp
->UserEvent
= &Event
;
51 Irp
->UserBuffer
=FileInformation
;
53 StackPtr
= IoGetNextIrpStackLocation(Irp
);
54 StackPtr
->MajorFunction
= IRP_MJ_QUERY_INFORMATION
;
55 StackPtr
->MinorFunction
= 0;
57 StackPtr
->Control
= 0;
58 StackPtr
->DeviceObject
= DeviceObject
;
59 StackPtr
->FileObject
= FileObject
;
61 StackPtr
->Parameters
.QueryFile
.FileInformationClass
=
63 StackPtr
->Parameters
.QueryFile
.Length
= Length
;
65 Status
= IoCallDriver(FileObject
->DeviceObject
,Irp
);
66 if (Status
==STATUS_PENDING
&& (FileObject
->Flags
& FO_SYNCHRONOUS_IO
))
68 KeWaitForSingleObject(&Event
,Executive
,KernelMode
,FALSE
,NULL
);
69 Status
= Irp
->IoStatus
.Status
;
77 NtQueryInformationFile (
79 PIO_STATUS_BLOCK IoStatusBlock
,
80 PVOID FileInformation
,
82 FILE_INFORMATION_CLASS FileInformationClass
85 PFILE_OBJECT FileObject
;
88 DPRINT("NtQueryInformationFile(Handle %x StatBlk %x FileInfo %x Length %d Class %d)\n",
93 FileInformationClass
);
95 Status
= ObReferenceObjectByHandle(FileHandle
,
101 if (!NT_SUCCESS(Status
))
105 DPRINT("FileObject %x\n", FileObject
);
106 Status
= internalQueryFileInfo(FileObject
, FileInformationClass
, IoStatusBlock
, Length
, FileInformation
, NULL
);
108 // ObDereferenceObject(FileObject); FIXME: Why will a Dereference here make the OS impossible to boot. Incorrect deferring somewhere else?
116 IoQueryFileInformation (
117 IN PFILE_OBJECT FileObject
,
118 IN FILE_INFORMATION_CLASS FileInformationClass
,
120 OUT PVOID FileInformation
,
121 OUT PULONG ReturnedLength
// FIXME: ReturnedLength not implemented
126 Status
= ObReferenceObjectByPointer(FileObject
,
127 FILE_READ_ATTRIBUTES
,
129 KernelMode
); // FIXME: Is KernelMode the correct choice here?
130 if (!NT_SUCCESS(Status
))
135 // ObDereferenceObject(FileObject); For some reason, ObDereference is NOT a good thing here... wish I knew why
136 return internalQueryFileInfo(FileObject
,FileInformationClass
,NULL
,Length
,FileInformation
,ReturnedLength
);
142 NtSetInformationFile (
144 PIO_STATUS_BLOCK IoStatusBlock
,
145 PVOID FileInformation
,
147 FILE_INFORMATION_CLASS FileInformationClass
151 PFILE_OBJECT FileObject
;
153 PIO_STACK_LOCATION StackPtr
;
157 "NtSetInformationFile(Handle %x StatBlk %x FileInfo %x Length %d Class %d)\n",
165 /* Get the file object from the file handle */
166 Status
= ObReferenceObjectByHandle(
168 FILE_WRITE_ATTRIBUTES
,
171 (PVOID
*) & FileObject
,
174 if (!NT_SUCCESS(Status
))
179 DPRINT("FileObject %x\n", FileObject
);
182 * Initialize an event object to wait
183 * on for the request.
191 * Build the IRP to be sent to the driver
194 Irp
= IoBuildSynchronousFsdRequest(
195 IRP_MJ_SET_INFORMATION
,
196 FileObject
->DeviceObject
,
204 StackPtr
= IoGetNextIrpStackLocation(Irp
);
205 StackPtr
->FileObject
= FileObject
;
206 StackPtr
->Parameters
.SetFile
.Length
= Length
;
207 StackPtr
->Parameters
.SetFile
.FileInformationClass
=
208 FileInformationClass
;
211 * Pass the IRP to the FSD (and wait for
214 DPRINT("FileObject->DeviceObject %x\n", FileObject
->DeviceObject
);
215 Status
= IoCallDriver(
216 FileObject
->DeviceObject
,
219 if ( (Status
== STATUS_PENDING
)
220 && (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
223 KeWaitForSingleObject(
230 Status
= Irp
->IoStatus
.Status
;
239 NtQueryAttributesFile (
240 IN POBJECT_ATTRIBUTES ObjectAttributes
,
250 NtQueryFullAttributesFile (
251 IN HANDLE FileHandle
,
262 IN HANDLE FileHandle
,
263 OUT PIO_STATUS_BLOCK IoStatusBlock
,
266 IN BOOLEAN ReturnSingleEntry
,
267 IN PVOID EaList OPTIONAL
,
268 IN ULONG EaListLength
,
269 IN PULONG EaIndex OPTIONAL
,
270 IN BOOLEAN RestartScan
280 IN HANDLE FileHandle
,
281 IN PIO_STATUS_BLOCK IoStatusBlock
,