From 8294118174b28a10daec3f763d8b5ab64104d1fa Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sun, 7 Jan 2018 14:16:11 +0100 Subject: [PATCH] [FASTFAT] Add a wrapper around FsRtlNotifyFullReportChange --- drivers/filesystems/fastfat/cleanup.c | 15 +-- drivers/filesystems/fastfat/create.c | 28 ++---- drivers/filesystems/fastfat/finfo.c | 130 +++++++++----------------- drivers/filesystems/fastfat/misc.c | 2 +- drivers/filesystems/fastfat/rw.c | 10 +- drivers/filesystems/fastfat/vfat.h | 22 +++++ 6 files changed, 82 insertions(+), 125 deletions(-) diff --git a/drivers/filesystems/fastfat/cleanup.c b/drivers/filesystems/fastfat/cleanup.c index d584dee8595..abdeb0b0c6c 100644 --- a/drivers/filesystems/fastfat/cleanup.c +++ b/drivers/filesystems/fastfat/cleanup.c @@ -124,16 +124,11 @@ VfatCleanupFile( { VfatDelEntry(DeviceExt, pFcb, NULL); - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&pFcb->PathNameU, - pFcb->PathNameU.Length - pFcb->LongNameU.Length, - NULL, - NULL, - vfatFCBIsDirectory(pFcb) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME, - FILE_ACTION_REMOVED, - NULL); + vfatReportChange(DeviceExt, + pFcb, + vfatFCBIsDirectory(pFcb) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME, + FILE_ACTION_REMOVED); } if (pFcb->OpenHandleCount != 0) diff --git a/drivers/filesystems/fastfat/create.c b/drivers/filesystems/fastfat/create.c index 1ba61fdd385..7ecc0ffae15 100644 --- a/drivers/filesystems/fastfat/create.c +++ b/drivers/filesystems/fastfat/create.c @@ -1002,29 +1002,19 @@ VfatCreateFile( if (Irp->IoStatus.Information == FILE_CREATED) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&pFcb->PathNameU, - pFcb->PathNameU.Length - pFcb->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(pFcb) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - FILE_ACTION_ADDED, - NULL); + vfatReportChange(DeviceExt, + pFcb, + (vfatFCBIsDirectory(pFcb) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + FILE_ACTION_ADDED); } else if (Irp->IoStatus.Information == FILE_OVERWRITTEN || Irp->IoStatus.Information == FILE_SUPERSEDED) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&pFcb->PathNameU, - pFcb->PathNameU.Length - pFcb->LongNameU.Length, - NULL, - NULL, - FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE, - FILE_ACTION_MODIFIED, - NULL); + vfatReportChange(DeviceExt, + pFcb, + FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE, + FILE_ACTION_MODIFIED); } pFcb->OpenHandleCount++; diff --git a/drivers/filesystems/fastfat/finfo.c b/drivers/filesystems/fastfat/finfo.c index 03b7d3cc93b..1befeebe00c 100644 --- a/drivers/filesystems/fastfat/finfo.c +++ b/drivers/filesystems/fastfat/finfo.c @@ -269,12 +269,10 @@ VfatSetBasicInformation( if (NotifyFilter != 0) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, NULL, NotifyFilter, FILE_ACTION_MODIFIED, - NULL); + vfatReportChange(DeviceExt, + FCB, + NotifyFilter, + FILE_ACTION_MODIFIED); } return STATUS_SUCCESS; @@ -822,29 +820,19 @@ VfatSetRenameInformation( if (FsRtlAreNamesEqual(&SourceFile, &NewFile, TRUE, NULL)) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(FCB) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - FILE_ACTION_RENAMED_OLD_NAME, - NULL); + vfatReportChange(DeviceExt, + FCB, + (vfatFCBIsDirectory(FCB) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + FILE_ACTION_RENAMED_OLD_NAME); Status = vfatRenameEntry(DeviceExt, FCB, &NewFile, TRUE); if (NT_SUCCESS(Status)) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(FCB) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - FILE_ACTION_RENAMED_NEW_NAME, - NULL); + vfatReportChange(DeviceExt, + FCB, + (vfatFCBIsDirectory(FCB) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + FILE_ACTION_RENAMED_NEW_NAME); } } else @@ -865,44 +853,29 @@ VfatSetRenameInformation( goto Cleanup; } - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(FCB) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - (DeletedTarget ? FILE_ACTION_REMOVED : FILE_ACTION_RENAMED_OLD_NAME), - NULL); + vfatReportChange(DeviceExt, + FCB, + (vfatFCBIsDirectory(FCB) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + (DeletedTarget ? FILE_ACTION_REMOVED : FILE_ACTION_RENAMED_OLD_NAME)); Status = vfatRenameEntry(DeviceExt, FCB, &NewFile, FALSE); if (NT_SUCCESS(Status)) { if (DeletedTarget) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE - | FILE_NOTIFY_CHANGE_LAST_ACCESS | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_EA, - FILE_ACTION_MODIFIED, - NULL); + vfatReportChange(DeviceExt, + FCB, + FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE + | FILE_NOTIFY_CHANGE_LAST_ACCESS | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_EA, + FILE_ACTION_MODIFIED); } else { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(FCB) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - FILE_ACTION_RENAMED_NEW_NAME, - NULL); + vfatReportChange(DeviceExt, + FCB, + (vfatFCBIsDirectory(FCB) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + FILE_ACTION_RENAMED_NEW_NAME); } } } @@ -936,44 +909,29 @@ VfatSetRenameInformation( UNREFERENCED_PARAMETER(NewReferences); #endif - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(FCB) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - FILE_ACTION_REMOVED, - NULL); + vfatReportChange(DeviceExt, + FCB, + (vfatFCBIsDirectory(FCB) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + FILE_ACTION_REMOVED); Status = VfatMoveEntry(DeviceExt, FCB, &NewFile, ParentFCB); if (NT_SUCCESS(Status)) { if (DeletedTarget) { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE - | FILE_NOTIFY_CHANGE_LAST_ACCESS | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_EA, - FILE_ACTION_MODIFIED, - NULL); + vfatReportChange(DeviceExt, + FCB, + FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE + | FILE_NOTIFY_CHANGE_LAST_ACCESS | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_EA, + FILE_ACTION_MODIFIED); } else { - FsRtlNotifyFullReportChange(DeviceExt->NotifySync, - &(DeviceExt->NotifyList), - (PSTRING)&FCB->PathNameU, - FCB->PathNameU.Length - FCB->LongNameU.Length, - NULL, - NULL, - (vfatFCBIsDirectory(FCB) ? - FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), - FILE_ACTION_ADDED, - NULL); + vfatReportChange(DeviceExt, + FCB, + (vfatFCBIsDirectory(FCB) ? + FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME), + FILE_ACTION_ADDED); } } } diff --git a/drivers/filesystems/fastfat/misc.c b/drivers/filesystems/fastfat/misc.c index d16507dd2ad..7797f37ab21 100644 --- a/drivers/filesystems/fastfat/misc.c +++ b/drivers/filesystems/fastfat/misc.c @@ -468,4 +468,4 @@ VfatCheckForDismount( } return Delete; -} +} diff --git a/drivers/filesystems/fastfat/rw.c b/drivers/filesystems/fastfat/rw.c index c945ee6044d..25114f25cf7 100644 --- a/drivers/filesystems/fastfat/rw.c +++ b/drivers/filesystems/fastfat/rw.c @@ -1070,15 +1070,7 @@ Metadata: Filter = FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_ATTRIBUTES; if (ByteOffset.QuadPart != OldFileSize.QuadPart) Filter |= FILE_NOTIFY_CHANGE_SIZE; - FsRtlNotifyFullReportChange(IrpContext->DeviceExt->NotifySync, - &(IrpContext->DeviceExt->NotifyList), - (PSTRING)&Fcb->PathNameU, - Fcb->PathNameU.Length - Fcb->LongNameU.Length, - NULL, - NULL, - Filter, - FILE_ACTION_MODIFIED, - NULL); + vfatReportChange(IrpContext->DeviceExt, Fcb, Filter, FILE_ACTION_MODIFIED); } } diff --git a/drivers/filesystems/fastfat/vfat.h b/drivers/filesystems/fastfat/vfat.h index b84b320573c..f6e2aa64525 100644 --- a/drivers/filesystems/fastfat/vfat.h +++ b/drivers/filesystems/fastfat/vfat.h @@ -602,6 +602,21 @@ vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt) return BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX); } +FORCEINLINE +VOID +vfatReportChange( + IN PDEVICE_EXTENSION DeviceExt, + IN PVFATFCB Fcb, + IN ULONG FilterMatch, + IN ULONG Action) +{ + FsRtlNotifyFullReportChange(DeviceExt->NotifySync, + &(DeviceExt->NotifyList), + (PSTRING)&Fcb->PathNameU, + Fcb->PathNameU.Length - Fcb->LongNameU.Length, + NULL, NULL, FilterMatch, Action, NULL); +} + #define vfatAddToStat(Vcb, Stat, Inc) \ { \ PSTATISTICS Stats = &(Vcb)->Statistics[KeGetCurrentProcessorNumber() % VfatGlobalData->NumberProcessors]; \ @@ -1033,6 +1048,13 @@ VfatCheckForDismount( IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Create); +VOID +vfatReportChange( + IN PDEVICE_EXTENSION DeviceExt, + IN PVFATFCB Fcb, + IN ULONG FilterMatch, + IN ULONG Action); + /* pnp.c */ NTSTATUS