[ros-diffs] [pschweitzer] 49758: [NTOSKRNL] - Implemented FsRtlPTeardownPerFileObjectContexts(), FsRtlLookupPerFileObjectContext(), FsRtlInsertPerFileObjectContext(), FsRtlRemovePerFileObjectContext() - Stubpl...

pschweitzer at svn.reactos.org pschweitzer at svn.reactos.org
Tue Nov 23 20:01:05 UTC 2010


Author: pschweitzer
Date: Tue Nov 23 20:01:04 2010
New Revision: 49758

URL: http://svn.reactos.org/svn/reactos?rev=49758&view=rev
Log:
[NTOSKRNL]
- Implemented FsRtlPTeardownPerFileObjectContexts(), FsRtlLookupPerFileObjectContext(), FsRtlInsertPerFileObjectContext(), FsRtlRemovePerFileObjectContext()
- Stubplemented IoGetFileObjectFilterContext(), IoChangeFileObjectFilterContext()
- Add support of per file object filter context to IopDeleteFile()
As ReactOS doesn't support file objects extensions, this doesn't work (blame Aleksey) - yet

Modified:
    trunk/reactos/ntoskrnl/fsrtl/filtrctx.c
    trunk/reactos/ntoskrnl/include/internal/fsrtl.h
    trunk/reactos/ntoskrnl/include/internal/io.h
    trunk/reactos/ntoskrnl/io/iomgr/file.c

Modified: trunk/reactos/ntoskrnl/fsrtl/filtrctx.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fsrtl/filtrctx.c?rev=49758&r1=49757&r2=49758&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/fsrtl/filtrctx.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/fsrtl/filtrctx.c [iso-8859-1] Tue Nov 23 20:01:04 2010
@@ -20,9 +20,26 @@
     LIST_ENTRY FilterContexts;
 } FILE_OBJECT_FILTER_CONTEXTS, *PFILE_OBJECT_FILTER_CONTEXTS;
 
+/*
+ * @implemented
+ */
 VOID
+NTAPI
 FsRtlPTeardownPerFileObjectContexts(IN PFILE_OBJECT FileObject)
 {
+    PFILE_OBJECT_FILTER_CONTEXTS FOContext = NULL;
+
+    ASSERT(FileObject);
+
+    if (!(FOContext = IoGetFileObjectFilterContext(FileObject)))
+    {
+        return;
+    }
+
+    ASSERT(IoChangeFileObjectFilterContext(FileObject, FOContext, FALSE) == STATUS_SUCCESS);
+    ASSERT(IsListEmpty(&(FOContext->FilterContexts)));
+
+    ExFreePoolWithTag(FOContext, 'FOCX');
 }
 
 
@@ -50,7 +67,7 @@
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 PFSRTL_PER_FILEOBJECT_CONTEXT
 NTAPI
@@ -58,8 +75,47 @@
                                 IN PVOID OwnerId OPTIONAL,
                                 IN PVOID InstanceId OPTIONAL)
 {
-    KeBugCheck(FILE_SYSTEM);
-    return FALSE;
+    PLIST_ENTRY NextEntry;
+    PFILE_OBJECT_FILTER_CONTEXTS FOContext = NULL;
+    PFSRTL_PER_FILEOBJECT_CONTEXT TmpPerFOContext, PerFOContext = NULL;
+
+    if (!FileObject || !(FOContext = IoGetFileObjectFilterContext(FileObject)))
+    {
+        return NULL;
+    }
+
+    ExAcquireFastMutex(&(FOContext->FilterContextsMutex));
+
+    /* If list is empty, no need to browse it */
+    if (!IsListEmpty(&(FOContext->FilterContexts)))
+    {
+        for (NextEntry = FOContext->FilterContexts.Flink;
+             NextEntry != &(FOContext->FilterContexts);
+             NextEntry = NextEntry->Flink)
+        {
+            /* If we don't have any criteria for search, first entry will be enough */
+            if (!OwnerId && !InstanceId)
+            {
+                PerFOContext = (PFSRTL_PER_FILEOBJECT_CONTEXT)NextEntry;
+                break;
+            }
+            /* Else, we've to find something that matches with the parameters. */
+            else
+            {
+                TmpPerFOContext = CONTAINING_RECORD(NextEntry, FSRTL_PER_FILEOBJECT_CONTEXT, Links);
+                if ((InstanceId && TmpPerFOContext->InstanceId == InstanceId && TmpPerFOContext->OwnerId == OwnerId) ||
+                    (OwnerId && TmpPerFOContext->OwnerId == OwnerId))
+                {
+                    PerFOContext = TmpPerFOContext;
+                    break;
+                }
+            }
+        }
+    }
+
+    ExReleaseFastMutex(&(FOContext->FilterContextsMutex));
+
+    return PerFOContext;
 }
 
 /*
@@ -105,21 +161,62 @@
             }
         }
     }
+
     ExReleaseFastMutex(AdvFcbHeader->FastMutex);
 
     return PerStreamContext;
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 NTSTATUS
 NTAPI
 FsRtlInsertPerFileObjectContext(IN PFILE_OBJECT FileObject,
                                 IN PFSRTL_PER_FILEOBJECT_CONTEXT Ptr)
 {
-    KeBugCheck(FILE_SYSTEM);
-    return STATUS_NOT_IMPLEMENTED;
+    PFILE_OBJECT_FILTER_CONTEXTS FOContext = NULL;
+
+    if (!FileObject)
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    if (!(FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION))
+    {
+        return STATUS_INVALID_DEVICE_REQUEST;
+    }
+
+    FOContext = IoGetFileObjectFilterContext(FileObject);
+    if (!FOContext)
+    {
+        FOContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(FILE_OBJECT_FILTER_CONTEXTS), 'FOCX');
+        if (!FOContext)
+        {
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
+
+        ExInitializeFastMutex(&(FOContext->FilterContextsMutex));
+        InitializeListHead(&(FOContext->FilterContexts));
+
+        if (!IoChangeFileObjectFilterContext(FileObject, FOContext, TRUE))
+        {
+            ExFreePoolWithTag(FOContext, 'FOCX');
+
+            FOContext = IoGetFileObjectFilterContext(FileObject);
+            if (!FOContext)
+            {
+                ASSERT(FALSE);
+                return STATUS_UNSUCCESSFUL;
+            }
+        }
+    }
+
+    ExAcquireFastMutex(&(FOContext->FilterContextsMutex));
+    InsertHeadList(&(FOContext->FilterContexts), &(Ptr->Links));
+    ExReleaseFastMutex(&(FOContext->FilterContextsMutex));
+
+    return STATUS_SUCCESS;
 }
 
 /*
@@ -142,16 +239,61 @@
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 PFSRTL_PER_FILEOBJECT_CONTEXT
 NTAPI
-FsRtlRemovePerFileObjectContext(IN PFILE_OBJECT PerFileObjectContext,
+FsRtlRemovePerFileObjectContext(IN PFILE_OBJECT FileObject,
                                 IN PVOID OwnerId OPTIONAL,
                                 IN PVOID InstanceId OPTIONAL)
 {
-    KeBugCheck(FILE_SYSTEM);
-    return NULL;
+    PLIST_ENTRY NextEntry;
+    PFILE_OBJECT_FILTER_CONTEXTS FOContext = NULL;
+    PFSRTL_PER_FILEOBJECT_CONTEXT TmpPerFOContext, PerFOContext = NULL;
+
+    if (!FileObject || !(FOContext = IoGetFileObjectFilterContext(FileObject)))
+    {
+        return NULL;
+    }
+
+    ExAcquireFastMutex(&(FOContext->FilterContextsMutex));
+
+    /* If list is empty, no need to browse it */
+    if (!IsListEmpty(&(FOContext->FilterContexts)))
+    {
+        for (NextEntry = FOContext->FilterContexts.Flink;
+             NextEntry != &(FOContext->FilterContexts);
+             NextEntry = NextEntry->Flink)
+        {
+            /* If we don't have any criteria for search, first entry will be enough */
+            if (!OwnerId && !InstanceId)
+            {
+                PerFOContext = (PFSRTL_PER_FILEOBJECT_CONTEXT)NextEntry;
+                break;
+            }
+            /* Else, we've to find something that matches with the parameters. */
+            else
+            {
+                TmpPerFOContext = CONTAINING_RECORD(NextEntry, FSRTL_PER_FILEOBJECT_CONTEXT, Links);
+                if ((InstanceId && TmpPerFOContext->InstanceId == InstanceId && TmpPerFOContext->OwnerId == OwnerId) ||
+                    (OwnerId && TmpPerFOContext->OwnerId == OwnerId))
+                {
+                    PerFOContext = TmpPerFOContext;
+                    break;
+                }
+            }
+        }
+
+        /* Finally remove entry from list */
+        if (PerFOContext)
+        {
+            RemoveEntryList(&(PerFOContext->Links));
+        }
+    }
+
+    ExReleaseFastMutex(&(FOContext->FilterContextsMutex));
+
+    return PerFOContext;
 }
 
 /*
@@ -197,6 +339,7 @@
                 }
             }
         }
+
         /* Finally remove entry from list */
         if (PerStreamContext)
         {

Modified: trunk/reactos/ntoskrnl/include/internal/fsrtl.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/fsrtl.h?rev=49758&r1=49757&r2=49758&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/fsrtl.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/fsrtl.h [iso-8859-1] Tue Nov 23 20:01:04 2010
@@ -54,6 +54,15 @@
 );
 
 //
+// File contexts Routines
+//
+VOID
+NTAPI
+FsRtlPTeardownPerFileObjectContexts(
+    IN PFILE_OBJECT FileObject
+);
+
+//
 // Global data inside the File System Runtime Library
 //
 extern PERESOURCE FsRtlPagingIoResources;

Modified: trunk/reactos/ntoskrnl/include/internal/io.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/io.h?rev=49758&r1=49757&r2=49758&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/io.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/io.h [iso-8859-1] Tue Nov 23 20:01:04 2010
@@ -1155,6 +1155,20 @@
     IN ULONG SystemHandleCount
 );
 
+PVOID
+NTAPI
+IoGetFileObjectFilterContext(
+    IN PFILE_OBJECT FileObject
+);
+
+NTSTATUS
+NTAPI
+IoChangeFileObjectFilterContext(
+    IN PFILE_OBJECT FileObject,
+    IN PVOID FilterContext,
+    IN BOOLEAN Define
+);
+
 //
 // I/O Timer Routines
 //

Modified: trunk/reactos/ntoskrnl/io/iomgr/file.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/file.c?rev=49758&r1=49757&r2=49758&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/file.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/file.c [iso-8859-1] Tue Nov 23 20:01:04 2010
@@ -1049,6 +1049,13 @@
             ExFreePool(FileObject->CompletionContext);
         }
 
+        /* Check if the FO had extension */
+        if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION)
+        {
+            /* Release filter context structure if any */
+            FsRtlPTeardownPerFileObjectContexts(FileObject);
+        }
+
         /* Check if dereference has been done yet */
         if (!DereferenceDone)
         {
@@ -1608,6 +1615,36 @@
 
     /* Return status */
     return Status;
+}
+
+PVOID
+NTAPI
+IoGetFileObjectFilterContext(IN PFILE_OBJECT FileObject)
+{
+    if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION)
+    {
+        UNIMPLEMENTED;
+        /* FIXME: return NULL for the moment ~ */
+        return NULL;
+    }
+
+    return NULL;
+}
+
+NTSTATUS
+NTAPI
+IoChangeFileObjectFilterContext(IN PFILE_OBJECT FileObject,
+                                IN PVOID FilterContext,
+                                IN BOOLEAN Define)
+{
+    if (!(FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION))
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    UNIMPLEMENTED;
+
+    return STATUS_NOT_IMPLEMENTED;
 }
 
 /* FUNCTIONS *****************************************************************/




More information about the Ros-diffs mailing list