https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2a182931b6dcbb213d342…
commit 2a182931b6dcbb213d342ad552f0d8b8e2ecd40b
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu Oct 4 22:24:52 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu Oct 4 22:24:52 2018 +0200
[NTOSKRNL] A bit of cleanup in Io*FilterContext()
---
ntoskrnl/io/iomgr/file.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/ntoskrnl/io/iomgr/file.c b/ntoskrnl/io/iomgr/file.c
index 860348a370..a8da317317 100644
--- a/ntoskrnl/io/iomgr/file.c
+++ b/ntoskrnl/io/iomgr/file.c
@@ -2441,7 +2441,7 @@ PVOID
NTAPI
IoGetFileObjectFilterContext(IN PFILE_OBJECT FileObject)
{
- if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION)
+ if (BooleanFlagOn(FileObject->Flags, FO_FILE_OBJECT_HAS_EXTENSION))
{
PFILE_OBJECT_EXTENSION FileObjectExtension;
@@ -2461,7 +2461,7 @@ IoChangeFileObjectFilterContext(IN PFILE_OBJECT FileObject,
ULONG_PTR Success;
PFILE_OBJECT_EXTENSION FileObjectExtension;
- if (!(FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION))
+ if (!BooleanFlagOn(FileObject->Flags, FO_FILE_OBJECT_HAS_EXTENSION))
{
return STATUS_INVALID_PARAMETER;
}
@@ -2472,7 +2472,7 @@ IoChangeFileObjectFilterContext(IN PFILE_OBJECT FileObject,
/* If define, just set the new value if not value is set
* Success will only contain old value. It is valid if it is NULL
*/
- Success = InterlockedCompareExchange((volatile LONG *)&FileObjectExtension->FilterContext, (ULONG_PTR)FilterContext, 0);
+ Success = (ULONG_PTR)InterlockedCompareExchangePointer(&FileObjectExtension->FilterContext, FilterContext, NULL);
}
else
{
@@ -2483,7 +2483,7 @@ IoChangeFileObjectFilterContext(IN PFILE_OBJECT FileObject,
* If it matches (and thus, we reset), Success will contain 0
* Otherwise, it will contain a non-zero value.
*/
- Success = InterlockedCompareExchange((volatile LONG *)&FileObjectExtension->FilterContext, 0, (ULONG_PTR)FilterContext) - (ULONG_PTR)FilterContext;
+ Success = (ULONG_PTR)InterlockedCompareExchangePointer(&FileObjectExtension->FilterContext, NULL, FilterContext) - (ULONG_PTR)FilterContext;
}
/* If success isn't 0, it means we failed somewhere (set or unset) */
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5f0d02eb52c6ebe3caf6a…
commit 5f0d02eb52c6ebe3caf6aa9c6315f5ca06bb89d3
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu Oct 4 19:30:11 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu Oct 4 19:30:39 2018 +0200
[NTOSKRNL] Implement IoChangeFileObjectFilterContext()
---
ntoskrnl/io/iomgr/file.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/ntoskrnl/io/iomgr/file.c b/ntoskrnl/io/iomgr/file.c
index 0a5e0b1d1a..860348a370 100644
--- a/ntoskrnl/io/iomgr/file.c
+++ b/ntoskrnl/io/iomgr/file.c
@@ -2458,14 +2458,41 @@ IoChangeFileObjectFilterContext(IN PFILE_OBJECT FileObject,
IN PVOID FilterContext,
IN BOOLEAN Define)
{
+ ULONG_PTR Success;
+ PFILE_OBJECT_EXTENSION FileObjectExtension;
+
if (!(FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION))
{
return STATUS_INVALID_PARAMETER;
}
- UNIMPLEMENTED;
+ FileObjectExtension = FileObject->FileObjectExtension;
+ if (Define)
+ {
+ /* If define, just set the new value if not value is set
+ * Success will only contain old value. It is valid if it is NULL
+ */
+ Success = InterlockedCompareExchange((volatile LONG *)&FileObjectExtension->FilterContext, (ULONG_PTR)FilterContext, 0);
+ }
+ else
+ {
+ /* If not define, we want to reset filter context.
+ * We will remove value (provided by the caller) and set NULL instead.
+ * This will only success if caller provides correct previous value.
+ * To catch whether it worked, we substract previous value to expect value:
+ * If it matches (and thus, we reset), Success will contain 0
+ * Otherwise, it will contain a non-zero value.
+ */
+ Success = InterlockedCompareExchange((volatile LONG *)&FileObjectExtension->FilterContext, 0, (ULONG_PTR)FilterContext) - (ULONG_PTR)FilterContext;
+ }
- return STATUS_NOT_IMPLEMENTED;
+ /* If success isn't 0, it means we failed somewhere (set or unset) */
+ if (Success != 0)
+ {
+ return STATUS_ALREADY_COMMITTED;
+ }
+
+ return STATUS_SUCCESS;
}
NTSTATUS
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e19e907a2c40fa90a238e…
commit e19e907a2c40fa90a238e78b146b5dfc3fe715a3
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu Oct 4 10:42:13 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu Oct 4 10:45:10 2018 +0200
[NTOSKRNL] Quickly check for alignment in NtRead/WriteFile
This quick check based on bits and operation is for 2^ based
sector sizes (most of the cases) and will perform faster than
the modulo operation which is still used in fallback in case
the sector size wouldn't be a power of 2.
---
ntoskrnl/io/iomgr/iofunc.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/ntoskrnl/io/iomgr/iofunc.c b/ntoskrnl/io/iomgr/iofunc.c
index 01a956505f..61fd88f8fd 100644
--- a/ntoskrnl/io/iomgr/iofunc.c
+++ b/ntoskrnl/io/iomgr/iofunc.c
@@ -2612,13 +2612,19 @@ NtReadFile(IN HANDLE FileHandle,
/* Perform additional checks for non-cached file access */
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING)
{
- /* Fail if Length is not sector size aligned */
+ /* Fail if Length is not sector size aligned
+ * Perform a quick check for 2^ sector sizes
+ * If it fails, try a more standard way
+ */
if ((DeviceObject->SectorSize != 0) &&
- (Length % DeviceObject->SectorSize != 0))
+ ((DeviceObject->SectorSize - 1) & Length) != 0)
{
- /* Release the file object and and fail */
- ObDereferenceObject(FileObject);
- return STATUS_INVALID_PARAMETER;
+ if (Length % DeviceObject->SectorSize != 0)
+ {
+ /* Release the file object and and fail */
+ ObDereferenceObject(FileObject);
+ return STATUS_INVALID_PARAMETER;
+ }
}
/* Fail if buffer doesn't match alignment requirements */
@@ -3649,13 +3655,19 @@ NtWriteFile(IN HANDLE FileHandle,
/* Perform additional checks for non-cached file access */
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING)
{
- /* Fail if Length is not sector size aligned */
+ /* Fail if Length is not sector size aligned
+ * Perform a quick check for 2^ sector sizes
+ * If it fails, try a more standard way
+ */
if ((DeviceObject->SectorSize != 0) &&
- (Length % DeviceObject->SectorSize != 0))
+ ((DeviceObject->SectorSize - 1) & Length) != 0)
{
- /* Release the file object and and fail */
- ObDereferenceObject(FileObject);
- return STATUS_INVALID_PARAMETER;
+ if (Length % DeviceObject->SectorSize != 0)
+ {
+ /* Release the file object and and fail */
+ ObDereferenceObject(FileObject);
+ return STATUS_INVALID_PARAMETER;
+ }
}
/* Fail if buffer doesn't match alignment requirements */