Add file object flags, complete DEVOBJ_EXTENSION, and implement: IoIsFileOriginRemote...
authorAlex Ionescu <aionescu@gmail.com>
Sat, 16 Apr 2005 19:38:14 +0000 (19:38 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Sat, 16 Apr 2005 19:38:14 +0000 (19:38 +0000)
svn path=/trunk/; revision=14639

reactos/include/ddk/iotypes.h
reactos/ntoskrnl/include/internal/io.h
reactos/ntoskrnl/io/device.c
reactos/ntoskrnl/io/file.c
reactos/ntoskrnl/io/irp.c
reactos/ntoskrnl/io/process.c

index 379cfc8..b46b06a 100644 (file)
@@ -645,6 +645,11 @@ typedef struct _IO_COMPLETION_CONTEXT
 #define FO_OPENED_CASE_SENSITIVE        0x00020000
 #define FO_HANDLE_CREATED               0x00040000
 #define FO_FILE_FAST_IO_READ            0x00080000
+#define FO_RANDOM_ACCESS                0x00100000
+#define FO_FILE_OPEN_CANCELLED          0x00200000
+#define FO_VOLUME_OPEN                  0x00400000
+#define FO_FILE_OBJECT_HAS_EXTENSION    0x00800000
+#define FO_REMOTE_ORIGIN                0x01000000
 
 typedef struct _FILE_OBJECT
 {
@@ -896,6 +901,12 @@ struct _FAST_IO_DISPATCH_TABLE
 #define DRVO_BOOTREINIT_REGISTERED 0x20L
 #define DRVO_LEGACY_RESOURCES 0x40L
 
+#define DOE_UNLOAD_PENDING    0x1
+#define DOE_DELETE_PENDING    0x2
+#define DOE_REMOVE_PENDING    0x4
+#define DOE_REMOVE_PROCESSED  0x8
+#define DOE_START_PENDING     0x10
+
 typedef struct _DRIVER_OBJECT
 {
    CSHORT Type;
index 6c6b41f..62667b8 100644 (file)
@@ -41,6 +41,7 @@
 
 #define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
 
+struct _DEVICE_OBJECT_POWER_EXTENSION;
 
 typedef struct _IO_COMPLETION_PACKET{
    PVOID             Key;
@@ -53,10 +54,17 @@ typedef struct _DEVOBJ_EXTENSION {
    CSHORT Type;
    USHORT Size;
    PDEVICE_OBJECT DeviceObject;
-   ULONG Unknown[3];
+   ULONG PowerFlags;
+   struct DEVICE_OBJECT_POWER_EXTENSION *Dope;
+   ULONG ExtensionFlags;
    struct _DEVICE_NODE *DeviceNode;
+   PDEVICE_OBJECT AttachedTo;
+   LONG StartIoCount;
+   LONG StartIoKey;
+   ULONG StartIoFlags;
+   struct _VPB *Vpb;
 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
-
+   
 typedef struct _PRIVATE_DRIVER_EXTENSIONS {
    struct _PRIVATE_DRIVER_EXTENSIONS *Link;
    PVOID ClientIdentificationAddress;
index 4351743..23f42d0 100644 (file)
@@ -247,30 +247,66 @@ IoGetDeviceAttachmentBaseRef(
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 NTSTATUS
 STDCALL
-IoGetDiskDeviceObject(
-    IN  PDEVICE_OBJECT  FileSystemDeviceObject,
-    OUT PDEVICE_OBJECT  *DiskDeviceObject
-    )
+IoGetDiskDeviceObject(IN  PDEVICE_OBJECT FileSystemDeviceObject,
+                      OUT PDEVICE_OBJECT *DiskDeviceObject)
 {
-       UNIMPLEMENTED;
-       return STATUS_NOT_IMPLEMENTED;
+    PDEVOBJ_EXTENSION DeviceExtension;
+    PVPB Vpb;
+    KIRQL OldIrql;
+    
+    /* Make sure there's a VPB */
+    if (!FileSystemDeviceObject->Vpb) return STATUS_INVALID_PARAMETER;
+    
+    /* Acquire it */
+    IoAcquireVpbSpinLock(&OldIrql);
+    
+    /* Get the Device Extension */
+    DeviceExtension = FileSystemDeviceObject->DeviceObjectExtension;
+    
+    /* Make sure this one has a VPB too */
+    Vpb = DeviceExtension->Vpb;
+    if (!Vpb) return STATUS_INVALID_PARAMETER;
+    
+    /* Make sure someone it's mounted */
+    if ((!Vpb->ReferenceCount) || (Vpb->Flags & VPB_MOUNTED)) return STATUS_VOLUME_DISMOUNTED;
+    
+    /* Return the Disk Device Object */
+    *DiskDeviceObject = Vpb->RealDevice;
+    
+    /* Release the lock */
+    IoReleaseVpbSpinLock(OldIrql);
+    return STATUS_SUCCESS;
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 PDEVICE_OBJECT
 STDCALL
-IoGetLowerDeviceObject(
-    IN  PDEVICE_OBJECT  DeviceObject
-    )
+IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject)
 {
-       UNIMPLEMENTED;
-       return 0;
+    PDEVOBJ_EXTENSION DeviceExtension = DeviceObject->DeviceObjectExtension;
+    PDEVICE_OBJECT LowerDeviceObject = NULL;
+    
+    /* Make sure it's not getting deleted */
+    if (DeviceExtension->ExtensionFlags & (DOE_UNLOAD_PENDING | 
+                                           DOE_DELETE_PENDING |
+                                           DOE_REMOVE_PENDING | 
+                                           DOE_REMOVE_PROCESSED))
+    {
+        /* Get the Lower Device Object */   
+        LowerDeviceObject = DeviceExtension->AttachedTo;      
+        
+        /* Reference it */
+        ObReferenceObject(LowerDeviceObject);
+    }
+
+    /* Return it */
+    return LowerDeviceObject;
 }
 
 /*
index f95a5fc..f4199cd 100644 (file)
@@ -265,16 +265,14 @@ IoCreateStreamFileObjectLite(
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 BOOLEAN
 STDCALL
-IoIsFileOriginRemote(
-    IN PFILE_OBJECT FileObject
-    )
+IoIsFileOriginRemote(IN PFILE_OBJECT FileObject)
 {
-       UNIMPLEMENTED;
-       return FALSE;
+    /* Return the flag status */
+    return (FileObject->Flags & FO_REMOTE_ORIGIN);
 }
 
 /*
index 7f3a770..500a6ff 100644 (file)
@@ -68,34 +68,6 @@ IoFreeIrp(PIRP Irp)
   ExFreePool(Irp);
 }
 
-/*
- * @unimplemented
- */
-ULONG
-STDCALL
-IoGetRequestorProcessId(
-    IN PIRP Irp
-    )
-{
-       UNIMPLEMENTED;
-       return 0;
-}
-
-/*
- * @unimplemented
- */
-NTSTATUS
-STDCALL
-IoGetRequestorSessionId(
-       IN PIRP Irp,
-       OUT PULONG pSessionId
-       )
-{
-       UNIMPLEMENTED;
-       return STATUS_NOT_IMPLEMENTED;
-}
-
-
 /*
  * @unimplemented
  */
index 4d04d24..5ccc0fa 100644 (file)
 /*
  * @implemented
  */
-PVOID STDCALL
+PVOID 
+STDCALL
 IoGetInitialStack(VOID)
 {
-  return(PsGetCurrentThread()->Tcb.InitialStack);
+    return(PsGetCurrentThread()->Tcb.InitialStack);
 }
 
-
 /*
  * @implemented
  */
-VOID STDCALL
+VOID 
+STDCALL
 IoGetStackLimits(OUT PULONG LowLimit,
-                OUT PULONG HighLimit)
+                 OUT PULONG HighLimit)
 {
-  *LowLimit = (ULONG)NtCurrentTeb()->Tib.StackLimit;
-  *HighLimit = (ULONG)NtCurrentTeb()->Tib.StackBase;
+    *LowLimit = (ULONG)NtCurrentTeb()->Tib.StackLimit;
+    *HighLimit = (ULONG)NtCurrentTeb()->Tib.StackBase;
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 BOOLEAN
 STDCALL
-IoIsSystemThread(
-    IN PETHREAD Thread
-    )
+IoIsSystemThread(IN PETHREAD Thread)
 {
-       UNIMPLEMENTED;
-       return FALSE;
+    /* Call the Ps Function */
+    return PsIsSystemThread(Thread);
 }
 
 /*
  * @implemented
  */
-PEPROCESS STDCALL
+PEPROCESS
+STDCALL
 IoThreadToProcess(IN PETHREAD Thread)
 {
-  return(Thread->ThreadsProcess);
+    return(Thread->ThreadsProcess);
 }
 
 
@@ -65,9 +65,31 @@ IoThreadToProcess(IN PETHREAD Thread)
 PEPROCESS STDCALL
 IoGetRequestorProcess(IN PIRP Irp)
 {
-  return(Irp->Tail.Overlay.Thread->ThreadsProcess);
+    return(Irp->Tail.Overlay.Thread->ThreadsProcess);
+}
+
+/*
+ * @implemented
+ */
+ULONG
+STDCALL
+IoGetRequestorProcessId(IN PIRP Irp)
+{
+    return (ULONG)(IoGetRequestorProcess(Irp)->UniqueProcessId);
 }
 
+/*
+ * @implemented
+ */
+NTSTATUS
+STDCALL
+IoGetRequestorSessionId(IN PIRP Irp,
+                        OUT PULONG pSessionId)
+{
+    *pSessionId = IoGetRequestorProcess(Irp)->SessionId;
+    
+    return STATUS_SUCCESS;
+}
 
 /**********************************************************************
  * NAME                                                        EXPORTED
@@ -84,14 +106,15 @@ IoGetRequestorProcess(IN PIRP Irp)
  *
  * @implemented
  */
-BOOLEAN STDCALL
+BOOLEAN 
+STDCALL
 IoSetThreadHardErrorMode(IN BOOLEAN HardErrorEnabled)
 {
-  BOOLEAN PreviousHEM = (BOOLEAN)(NtCurrentTeb()->HardErrorDisabled);
+    BOOLEAN PreviousHEM = (BOOLEAN)(NtCurrentTeb()->HardErrorDisabled);
 
-  NtCurrentTeb()->HardErrorDisabled = ((TRUE == HardErrorEnabled) ? FALSE : TRUE);
+    NtCurrentTeb()->HardErrorDisabled = ((TRUE == HardErrorEnabled) ? FALSE : TRUE);
 
-  return((TRUE == PreviousHEM) ? FALSE : TRUE);
+    return((TRUE == PreviousHEM) ? FALSE : TRUE);
 }
 
 /* EOF */