*** empty log message ***
[reactos.git] / reactos / ntoskrnl / io / file.c
index 1064b46..15b279a 100644 (file)
 /* INCLUDES *****************************************************************/
 
 #include <ddk/ntddk.h>
+#include <internal/io.h>
 
-#define NDEBUG
+//#define NDEBUG
 #include <internal/debug.h>
 
 /* FUNCTIONS *****************************************************************/
 
-NTSTATUS NtQueryInformationFile(HANDLE FileHandle,
-                               PIO_STATUS_BLOCK IoStatusBlock,
-                               PVOID FileInformation,
-                               ULONG Length,
-                               FILE_INFORMATION_CLASS FileInformationClass)
+NTSTATUS STDCALL NtQueryInformationFile(HANDLE FileHandle,
+                                       PIO_STATUS_BLOCK IoStatusBlock,
+                                       PVOID FileInformation,
+                                       ULONG Length,
+                                       FILE_INFORMATION_CLASS FileInformationClass)
 {
   return ZwQueryInformationFile(FileHandle,
                                 IoStatusBlock,
@@ -30,11 +31,11 @@ NTSTATUS NtQueryInformationFile(HANDLE FileHandle,
                                 FileInformationClass);
 }
 
-NTSTATUS ZwQueryInformationFile(HANDLE FileHandle,
-                               PIO_STATUS_BLOCK IoStatusBlock,
-                               PVOID FileInformation,
-                               ULONG Length,
-                               FILE_INFORMATION_CLASS FileInformationClass)
+NTSTATUS STDCALL ZwQueryInformationFile(HANDLE FileHandle,
+                                       PIO_STATUS_BLOCK IoStatusBlock,
+                                       PVOID FileInformation,
+                                       ULONG Length,
+                                       FILE_INFORMATION_CLASS FileInformationClass)
 {
   NTSTATUS Status;
   PFILE_OBJECT FileObject;
@@ -52,11 +53,11 @@ NTSTATUS ZwQueryInformationFile(HANDLE FileHandle,
   /*  Get the file object from the file handle  */
   Status = ObReferenceObjectByHandle(FileHandle,
                                      FILE_READ_ATTRIBUTES,
-                                     NULL,
+                                     IoFileType,
                                      UserMode,
                                      (PVOID *) &FileObject,
                                      NULL);
-  if (Status != STATUS_SUCCESS)
+  if (!NT_SUCCESS(Status))
     {
       return Status;
     }
@@ -109,7 +110,58 @@ NTSTATUS ZwSetInformationFile(HANDLE FileHandle,
                              ULONG Length,
                              FILE_INFORMATION_CLASS FileInformationClass)
 {
-  UNIMPLEMENTED;
+  NTSTATUS Status;
+  PFILE_OBJECT FileObject;
+  PIRP Irp;
+  PIO_STACK_LOCATION StackPtr;
+  KEVENT Event;
+   
+  DPRINT("ZwSetInformation(Handle %x StatBlk %x FileInfo %x Length %d Class %d)\n",
+         FileHandle,
+         IoStatusBlock,
+         FileInformation,
+         Length,
+         FileInformationClass);
+   
+  /*  Get the file object from the file handle  */
+  Status = ObReferenceObjectByHandle(FileHandle,
+                                     FILE_WRITE_ATTRIBUTES,
+                                     IoFileType,
+                                     UserMode,
+                                     (PVOID *) &FileObject,
+                                     NULL);
+  if (!NT_SUCCESS(Status))
+    {
+      return Status;
+    }
+  DPRINT("FileObject %x\n", FileObject);
+   
+  /*  initialize an event object to wait on for the request  */
+  KeInitializeEvent(&Event, NotificationEvent, FALSE);
+
+  /*  build the IRP to be sent to the driver for the request  */
+  Irp = IoBuildSynchronousFsdRequest(IRP_MJ_SET_INFORMATION,
+                                     FileObject->DeviceObject,
+                                     FileInformation,
+                                     Length,
+                                     0,
+                                     &Event,
+                                     IoStatusBlock);
+  StackPtr = IoGetNextIrpStackLocation(Irp);
+  StackPtr->FileObject = FileObject;
+  StackPtr->Parameters.SetFile.Length = Length;
+  StackPtr->Parameters.SetFile.FileInformationClass = FileInformationClass;
+   
+  /*  Pass the IRP to the FSD (and wait for it if required) */
+  DPRINT("FileObject->DeviceObject %x\n", FileObject->DeviceObject);
+  Status = IoCallDriver(FileObject->DeviceObject, Irp);
+  if (Status == STATUS_PENDING  && (FileObject->Flags & FO_SYNCHRONOUS_IO))
+    {
+      KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+      Status = Irp->IoStatus.Status;
+    } 
+
+  return Status;
 }
 
 PGENERIC_MAPPING IoGetFileObjectGenericMapping(VOID)