[FASTFAT]
authorpschweitzer <pschweitzer@97493ccd-5924-5043-b1f5-66cb403b36ce>
Fri, 17 Feb 2017 17:58:18 +0000 (17:58 +0000)
committerpschweitzer <pschweitzer@97493ccd-5924-5043-b1f5-66cb403b36ce>
Fri, 17 Feb 2017 17:58:18 +0000 (17:58 +0000)
More FastFAT cleanup.
Except a light performances boost due to useless checks removal in read/write and to some functions inlining

More to follow...

git-svn-id: file:///srv/svn/reactos/trunk@73819 97493ccd-5924-5043-b1f5-66cb403b36ce

16 files changed:
reactos/drivers/filesystems/fastfat/blockdev.c
reactos/drivers/filesystems/fastfat/cleanup.c
reactos/drivers/filesystems/fastfat/close.c
reactos/drivers/filesystems/fastfat/create.c
reactos/drivers/filesystems/fastfat/dir.c
reactos/drivers/filesystems/fastfat/direntry.c
reactos/drivers/filesystems/fastfat/dirwr.c
reactos/drivers/filesystems/fastfat/fastio.c
reactos/drivers/filesystems/fastfat/fcb.c
reactos/drivers/filesystems/fastfat/finfo.c
reactos/drivers/filesystems/fastfat/flush.c
reactos/drivers/filesystems/fastfat/fsctl.c
reactos/drivers/filesystems/fastfat/misc.c
reactos/drivers/filesystems/fastfat/rw.c
reactos/drivers/filesystems/fastfat/vfat.h
reactos/drivers/filesystems/fastfat/volume.c

index 419390f..2dc962f 100644 (file)
@@ -56,7 +56,7 @@ VfatReadWritePartialCompletion(
     }
 
     if (0 == InterlockedDecrement((PLONG)&IrpContext->RefCount) &&
-        IrpContext->Flags & IRPCONTEXT_PENDINGRETURNED)
+        BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_PENDINGRETURNED))
     {
         KeSetEvent(&IrpContext->Event, IO_NO_INCREMENT, FALSE);
     }
index 1f3bdcd..7c223c8 100644 (file)
@@ -35,7 +35,7 @@ VfatCleanupFile(
     if (!pFcb)
         return STATUS_SUCCESS;
 
-    if (pFcb->Flags & FCB_IS_VOLUME)
+    if (BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME))
     {
         pFcb->OpenHandleCount--;
 
@@ -76,12 +76,12 @@ VfatCleanupFile(
                                NULL);
         }
 
-        if (pFcb->Flags & FCB_IS_DIRTY)
+        if (BooleanFlagOn(pFcb->Flags, FCB_IS_DIRTY))
         {
             VfatUpdateEntry (pFcb);
         }
 
-        if (pFcb->Flags & FCB_DELETE_PENDING &&
+        if (BooleanFlagOn(pFcb->Flags, FCB_DELETE_PENDING) &&
             pFcb->OpenHandleCount == 0)
         {
             if (vfatFCBIsDirectory(pFcb) &&
@@ -109,7 +109,7 @@ VfatCleanupFile(
         /* Uninitialize the cache (should be done even if caching was never initialized) */
         CcUninitializeCacheMap(FileObject, &pFcb->RFCB.FileSize, NULL);
 
-        if (pFcb->Flags & FCB_DELETE_PENDING &&
+        if (BooleanFlagOn(pFcb->Flags, FCB_DELETE_PENDING) &&
             pFcb->OpenHandleCount == 0)
         {
             VfatDelEntry(DeviceExt, pFcb, NULL);
@@ -120,8 +120,8 @@ VfatCleanupFile(
                                         pFcb->PathNameU.Length - pFcb->LongNameU.Length,
                                         NULL,
                                         NULL,
-                                        ((*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
-                                        FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
+                                        VfatIsDirectoryEmpty(pFcb) ?
+                                        FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME,
                                         FILE_ACTION_REMOVED,
                                         NULL);
         }
@@ -138,7 +138,7 @@ VfatCleanupFile(
     }
 
 #ifdef ENABLE_SWAPOUT
-    if (DeviceExt->Flags & VCB_DISMOUNT_PENDING)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_DISMOUNT_PENDING))
     {
         VfatCheckForDismount(DeviceExt, FALSE);
     }
index a5af6c7..1019111 100644 (file)
@@ -39,7 +39,7 @@ VfatCloseFile(
         return STATUS_SUCCESS;
     }
 
-    if (pFcb->Flags & FCB_IS_VOLUME)
+    if (BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME))
     {
         DPRINT("Volume\n");
         FileObject->FsContext2 = NULL;
index abc361d..59f8042 100644 (file)
@@ -57,7 +57,7 @@ vfat8Dot3ToString(
 
     RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
 
-    if (pEntry->lCase & VFAT_CASE_LOWER_BASE)
+    if (BooleanFlagOn(pEntry->lCase, VFAT_CASE_LOWER_BASE))
     {
         RtlDowncaseUnicodeString(NameU, NameU, FALSE);
     }
@@ -81,7 +81,7 @@ vfat8Dot3ToString(
         StringA.Length++);
         StringA.MaximumLength = StringA.Length;
         RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
-        if (pEntry->lCase & VFAT_CASE_LOWER_EXT)
+        if (BooleanFlagOn(pEntry->lCase, VFAT_CASE_LOWER_EXT))
         {
             RtlDowncaseUnicodeString(NameU, NameU, FALSE);
         }
@@ -119,7 +119,7 @@ ReadVolumeLabel(
     *(Vpb->VolumeLabel) = 0;
     Vpb->VolumeLabelLength = 0;
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
     {
         SizeDirEntry = sizeof(FATX_DIR_ENTRY);
         EntriesPerPage = FATX_ENTRIES_PER_PAGE;
@@ -151,7 +151,7 @@ ReadVolumeLabel(
             if (ENTRY_VOLUME(DeviceExt, Entry))
             {
                 /* copy volume label */
-                if (DeviceExt->Flags & VCB_IS_FATX)
+                if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
                 {
                     StringO.Buffer = (PCHAR)Entry->FatX.Filename;
                     StringO.MaximumLength = StringO.Length = Entry->FatX.FilenameLength;
@@ -259,7 +259,7 @@ FindFile(
         if (rcFcb)
         {
             ULONG startIndex = rcFcb->startIndex;
-            if ((rcFcb->Flags & FCB_IS_FATX_ENTRY) && !vfatFCBIsRoot(Parent))
+            if (BooleanFlagOn(rcFcb->Flags, FCB_IS_FATX_ENTRY) && !vfatFCBIsRoot(Parent))
             {
                 startIndex += 2;
             }
@@ -436,7 +436,7 @@ VfatOpenFile(
     }
 
     /* Fail, if we try to overwrite an existing directory */
-    if ((!(RequestedOptions & FILE_DIRECTORY_FILE) && (*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY)) &&
+    if ((!BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE) && vfatFCBIsDirectory(Fcb)) &&
         (RequestedDisposition == FILE_OVERWRITE ||
          RequestedDisposition == FILE_OVERWRITE_IF ||
          RequestedDisposition == FILE_SUPERSEDE))
@@ -445,14 +445,14 @@ VfatOpenFile(
         return STATUS_OBJECT_NAME_COLLISION;
     }
 
-    if (Fcb->Flags & FCB_DELETE_PENDING)
+    if (BooleanFlagOn(Fcb->Flags, FCB_DELETE_PENDING))
     {
         vfatReleaseFCB(DeviceExt, Fcb);
         return STATUS_DELETE_PENDING;
     }
 
     /* Fail, if we try to overwrite a read-only file */
-    if ((*Fcb->Attributes & FILE_ATTRIBUTE_READONLY) &&
+    if (vfatFCBIsReadOnly(Fcb) &&
         (RequestedDisposition == FILE_OVERWRITE ||
          RequestedDisposition == FILE_OVERWRITE_IF))
     {
@@ -460,7 +460,7 @@ VfatOpenFile(
         return STATUS_ACCESS_DENIED;
     }
 
-    if ((*Fcb->Attributes & FILE_ATTRIBUTE_READONLY) &&
+    if (vfatFCBIsReadOnly(Fcb) &&
         (RequestedOptions & FILE_DELETE_ON_CLOSE))
     {
         vfatReleaseFCB(DeviceExt, Fcb);
@@ -470,7 +470,7 @@ VfatOpenFile(
     if ((vfatFCBIsRoot(Fcb) ||
          (Fcb->LongNameU.Length == sizeof(WCHAR) && Fcb->LongNameU.Buffer[0] == L'.') ||
          (Fcb->LongNameU.Length == 2 * sizeof(WCHAR) && Fcb->LongNameU.Buffer[0] == L'.' && Fcb->LongNameU.Buffer[1] == L'.')) &&
-        (RequestedOptions & FILE_DELETE_ON_CLOSE))
+        BooleanFlagOn(RequestedOptions, FILE_DELETE_ON_CLOSE))
     {
         // we cannot delete a '.', '..' or the root directory
         vfatReleaseFCB(DeviceExt, Fcb);
@@ -513,32 +513,32 @@ VfatCreateFile(
     Stack = IoGetCurrentIrpStackLocation(Irp);
     RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff);
     RequestedOptions = Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
-    PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
-    OpenTargetDir = (Stack->Flags & SL_OPEN_TARGET_DIRECTORY) ? TRUE : FALSE;
+    PagingFileCreate = BooleanFlagOn(Stack->Flags, SL_OPEN_PAGING_FILE);
+    OpenTargetDir = BooleanFlagOn(Stack->Flags, SL_OPEN_TARGET_DIRECTORY);
 
     FileObject = Stack->FileObject;
     DeviceExt = DeviceObject->DeviceExtension;
 
-    if (Stack->Parameters.Create.Options & FILE_OPEN_BY_FILE_ID)
+    if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_OPEN_BY_FILE_ID))
     {
         return STATUS_NOT_IMPLEMENTED;
     }
 
     /* Check their validity. */
-    if (RequestedOptions & FILE_DIRECTORY_FILE &&
+    if (BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE) &&
         RequestedDisposition == FILE_SUPERSEDE)
     {
         return STATUS_INVALID_PARAMETER;
     }
 
-    if (RequestedOptions & FILE_DIRECTORY_FILE &&
-        RequestedOptions & FILE_NON_DIRECTORY_FILE)
+    if (BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE) &&
+        BooleanFlagOn(RequestedOptions, FILE_NON_DIRECTORY_FILE))
     {
         return STATUS_INVALID_PARAMETER;
     }
 
     /* Deny create if the volume is locked */
-    if (DeviceExt->Flags & VCB_VOLUME_LOCKED)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_VOLUME_LOCKED))
     {
         return STATUS_ACCESS_DENIED;
     }
@@ -569,7 +569,7 @@ VfatCreateFile(
             return STATUS_INVALID_PARAMETER;
         }
 
-        if (RequestedOptions & FILE_DELETE_ON_CLOSE)
+        if (BooleanFlagOn(RequestedOptions, FILE_DELETE_ON_CLOSE))
         {
             return STATUS_CANNOT_DELETE;
         }
@@ -798,11 +798,11 @@ VfatCreateFile(
             RequestedDisposition == FILE_SUPERSEDE)
         {
             Attributes = Stack->Parameters.Create.FileAttributes & ~FILE_ATTRIBUTE_NORMAL;
-            if (!(RequestedOptions & FILE_DIRECTORY_FILE))
+            if (!BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE))
                 Attributes |= FILE_ATTRIBUTE_ARCHIVE;
             vfatSplitPathName(&PathNameU, NULL, &FileNameU);
             Status = VfatAddEntry(DeviceExt, &FileNameU, &pFcb, ParentFcb, RequestedOptions,
-                                  (UCHAR)(Attributes & FILE_ATTRIBUTE_VALID_FLAGS), NULL);
+                                  (UCHAR)FlagOn(Attributes, FILE_ATTRIBUTE_VALID_FLAGS), NULL);
             vfatReleaseFCB(DeviceExt, ParentFcb);
             if (NT_SUCCESS(Status))
             {
@@ -875,22 +875,22 @@ VfatCreateFile(
         /*
          * Check the file has the requested attributes
          */
-        if (RequestedOptions & FILE_NON_DIRECTORY_FILE &&
-            *pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY)
+        if (BooleanFlagOn(RequestedOptions, FILE_NON_DIRECTORY_FILE) &&
+            vfatFCBIsDirectory(pFcb))
         {
             VfatCloseFile (DeviceExt, FileObject);
             return STATUS_FILE_IS_A_DIRECTORY;
         }
-        if (RequestedOptions & FILE_DIRECTORY_FILE &&
-            !(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY))
+        if (BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE) &&
+            !vfatFCBIsDirectory(pFcb))
         {
             VfatCloseFile (DeviceExt, FileObject);
             return STATUS_NOT_A_DIRECTORY;
         }
 #ifndef USE_ROS_CC_AND_FS
-        if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY))
+        if (!vfatFCBIsDirectory(pFcb))
         {
-            if (Stack->Parameters.Create.SecurityContext->DesiredAccess & FILE_WRITE_DATA ||
+            if (BooleanFlagOn(Stack->Parameters.Create.SecurityContext->DesiredAccess, FILE_WRITE_DATA) ||
                 RequestedDisposition == FILE_OVERWRITE ||
                 RequestedDisposition == FILE_OVERWRITE_IF ||
                 (RequestedOptions & FILE_DELETE_ON_CLOSE))
@@ -901,8 +901,8 @@ VfatCreateFile(
                     DPRINT1("%d %d %d\n", Stack->Parameters.Create.SecurityContext->DesiredAccess & FILE_WRITE_DATA,
                             RequestedDisposition == FILE_OVERWRITE, RequestedDisposition == FILE_OVERWRITE_IF);
                     VfatCloseFile (DeviceExt, FileObject);
-                    return (RequestedOptions & FILE_DELETE_ON_CLOSE) ? STATUS_CANNOT_DELETE
-                                                                     : STATUS_SHARING_VIOLATION;
+                    return (BooleanFlagOn(RequestedOptions, FILE_DELETE_ON_CLOSE)) ? STATUS_CANNOT_DELETE
+                                                                                   : STATUS_SHARING_VIOLATION;
                 }
             }
         }
@@ -919,7 +919,7 @@ VfatCreateFile(
              */
             if (pFcb->RefCount > 1)
             {
-                if(!(pFcb->Flags & FCB_IS_PAGE_FILE))
+                if(!BooleanFlagOn(pFcb->Flags, FCB_IS_PAGE_FILE))
                 {
                     VfatCloseFile(DeviceExt, FileObject);
                     return STATUS_INVALID_PARAMETER;
@@ -932,7 +932,7 @@ VfatCreateFile(
         }
         else
         {
-            if (pFcb->Flags & FCB_IS_PAGE_FILE)
+            if (BooleanFlagOn(pFcb->Flags, FCB_IS_PAGE_FILE))
             {
                 VfatCloseFile(DeviceExt, FileObject);
                 return STATUS_INVALID_PARAMETER;
@@ -943,7 +943,7 @@ VfatCreateFile(
             RequestedDisposition == FILE_OVERWRITE_IF ||
             RequestedDisposition == FILE_SUPERSEDE)
         {
-            if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY))
+            if (!vfatFCBIsDirectory(pFcb))
             {
                 *pFcb->Attributes = Stack->Parameters.Create.FileAttributes & ~FILE_ATTRIBUTE_NORMAL;
                 *pFcb->Attributes |= FILE_ATTRIBUTE_ARCHIVE;
@@ -999,7 +999,7 @@ VfatCreateFile(
                                     pFcb->PathNameU.Length - pFcb->LongNameU.Length,
                                     NULL,
                                     NULL,
-                                    ((*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                    (vfatFCBIsDirectory(pFcb) ?
                                     FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                     FILE_ACTION_ADDED,
                                     NULL);
@@ -1034,7 +1034,7 @@ VfatCreate(
         return STATUS_SUCCESS;
     }
 
-    if (!(IrpContext->Flags & IRPCONTEXT_CANWAIT))
+    if (!BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))
     {
         return VfatMarkIrpContextForQueue(IrpContext);
     }
index c664af1..8c5e19a 100644 (file)
@@ -127,7 +127,7 @@ VfatGetFileDirectoryInformation(
                   DirContext->LongNameU.Buffer,
                   DirContext->LongNameU.Length);
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
     {
         FsdDosDateTimeToSystemTime(DeviceExt,
                                    DirContext->DirEntry.FatX.CreationDate,
@@ -144,7 +144,7 @@ VfatGetFileDirectoryInformation(
 
         pInfo->ChangeTime = pInfo->LastWriteTime;
 
-        if (DirContext->DirEntry.FatX.Attrib & FILE_ATTRIBUTE_DIRECTORY)
+        if (BooleanFlagOn(DirContext->DirEntry.FatX.Attrib, FILE_ATTRIBUTE_DIRECTORY))
         {
             pInfo->EndOfFile.QuadPart = 0;
             pInfo->AllocationSize.QuadPart = 0;
@@ -178,7 +178,7 @@ VfatGetFileDirectoryInformation(
 
         pInfo->ChangeTime = pInfo->LastWriteTime;
 
-        if (DirContext->DirEntry.Fat.Attrib & FILE_ATTRIBUTE_DIRECTORY)
+        if (BooleanFlagOn(DirContext->DirEntry.Fat.Attrib, FILE_ATTRIBUTE_DIRECTORY))
         {
             pInfo->EndOfFile.QuadPart = 0;
             pInfo->AllocationSize.QuadPart = 0;
@@ -220,7 +220,7 @@ VfatGetFileFullDirectoryInformation(
                   DirContext->LongNameU.Buffer,
                   DirContext->LongNameU.Length);
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
     {
         FsdDosDateTimeToSystemTime(DeviceExt,
                                    DirContext->DirEntry.FatX.CreationDate,
@@ -285,7 +285,7 @@ VfatGetFileBothInformation(
 
     pInfo->EaSize = 0;
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
     {
         pInfo->FileNameLength = DirContext->LongNameU.Length;
 
@@ -314,7 +314,7 @@ VfatGetFileBothInformation(
 
         pInfo->ChangeTime = pInfo->LastWriteTime;
 
-        if (DirContext->DirEntry.FatX.Attrib & FILE_ATTRIBUTE_DIRECTORY)
+        if (BooleanFlagOn(DirContext->DirEntry.FatX.Attrib, FILE_ATTRIBUTE_DIRECTORY))
         {
             pInfo->EndOfFile.QuadPart = 0;
             pInfo->AllocationSize.QuadPart = 0;
@@ -364,7 +364,7 @@ VfatGetFileBothInformation(
 
         pInfo->ChangeTime = pInfo->LastWriteTime;
 
-        if (DirContext->DirEntry.Fat.Attrib & FILE_ATTRIBUTE_DIRECTORY)
+        if (BooleanFlagOn(DirContext->DirEntry.Fat.Attrib, FILE_ATTRIBUTE_DIRECTORY))
         {
             pInfo->EndOfFile.QuadPart = 0;
             pInfo->AllocationSize.QuadPart = 0;
@@ -497,11 +497,11 @@ DoQuery(
         pCcb->SearchPattern.Length = sizeof(WCHAR);
     }
 
-    if (IrpContext->Stack->Flags & SL_INDEX_SPECIFIED)
+    if (BooleanFlagOn(IrpContext->Stack->Flags, SL_INDEX_SPECIFIED))
     {
         DirContext.DirIndex = pCcb->Entry = Stack->Parameters.QueryDirectory.FileIndex;
     }
-    else if (FirstQuery || (IrpContext->Stack->Flags & SL_RESTART_SCAN))
+    else if (FirstQuery || BooleanFlagOn(IrpContext->Stack->Flags, SL_RESTART_SCAN))
     {
         DirContext.DirIndex = pCcb->Entry = 0;
     }
@@ -579,7 +579,7 @@ DoQuery(
         pCcb->Entry = ++DirContext.DirIndex;
         BufferLength -= Buffer0->NextEntryOffset;
 
-        if (IrpContext->Stack->Flags & SL_RETURN_SINGLE_ENTRY)
+        if (BooleanFlagOn(IrpContext->Stack->Flags, SL_RETURN_SINGLE_ENTRY))
             break;
 
         Buffer += Buffer0->NextEntryOffset;
@@ -653,7 +653,7 @@ VfatDirectoryControl(
             break;
     }
 
-    if (Status == STATUS_PENDING && IrpContext->Flags & IRPCONTEXT_COMPLETE)
+    if (Status == STATUS_PENDING && BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_COMPLETE))
     {
         return VfatMarkIrpContextForQueue(IrpContext);
     }
index 28effc1..702a8eb 100644 (file)
@@ -27,7 +27,7 @@ vfatDirEntryGetFirstCluster(
         cluster = pFatDirEntry->Fat.FirstCluster |
                  (pFatDirEntry->Fat.FirstClusterHigh << 16);
     }
-    else if (pDeviceExt->Flags & VCB_IS_FATX)
+    else if (BooleanFlagOn(pDeviceExt->Flags, VCB_IS_FATX))
     {
         cluster = pFatDirEntry->FatX.FirstCluster;
     }
@@ -172,7 +172,7 @@ BOOLEAN
 VfatIsDirectoryEmpty(
     PVFATFCB Fcb)
 {
-    if (Fcb->Flags & FCB_IS_FATX_ENTRY)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_FATX_ENTRY))
         return FATXIsDirectoryEmpty(Fcb);
     else
         return FATIsDirectoryEmpty(Fcb);
index f032268..e3e824f 100644 (file)
@@ -31,7 +31,7 @@ VfatUpdateEntry(
 
     ASSERT(pFcb);
 
-    if (pFcb->Flags & FCB_IS_FATX_ENTRY)
+    if (BooleanFlagOn(pFcb->Flags, FCB_IS_FATX_ENTRY))
     {
         SizeDirEntry = sizeof(FATX_DIR_ENTRY);
         dirIndex = pFcb->startIndex;
@@ -44,7 +44,7 @@ VfatUpdateEntry(
 
     DPRINT("updEntry dirIndex %u, PathName \'%wZ\'\n", dirIndex, &pFcb->PathNameU);
 
-    if (vfatFCBIsRoot(pFcb) || (pFcb->Flags & (FCB_IS_FAT|FCB_IS_VOLUME)))
+    if (vfatFCBIsRoot(pFcb) || BooleanFlagOn(pFcb->Flags, FCB_IS_FAT | FCB_IS_VOLUME))
     {
         return STATUS_SUCCESS;
     }
@@ -90,7 +90,7 @@ vfatRenameEntry(
 
     DPRINT("vfatRenameEntry(%p, %p, %wZ, %d)\n", DeviceExt, pFcb, FileName, CaseChangeOnly);
 
-    if (pFcb->Flags & FCB_IS_FATX_ENTRY)
+    if (BooleanFlagOn(pFcb->Flags, FCB_IS_FATX_ENTRY))
     {
         VFAT_DIRENTRY_CONTEXT DirContext;
 
@@ -162,7 +162,7 @@ vfatFindDirSpace(
     ULONG SizeDirEntry;
     FileOffset.QuadPart = 0;
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
         SizeDirEntry = sizeof(FATX_DIR_ENTRY);
     else
         SizeDirEntry = sizeof(FAT_DIR_ENTRY);
@@ -304,6 +304,7 @@ FATAddEntry(
     BOOLEAN BaseAllLower, BaseAllUpper;
     BOOLEAN ExtensionAllLower, ExtensionAllUpper;
     BOOLEAN InExtension;
+    BOOLEAN IsDirectory;
     WCHAR c;
     ULONG CurrentCluster;
     LARGE_INTEGER SystemTime, FileOffset;
@@ -323,6 +324,7 @@ FATAddEntry(
     DPRINT("addEntry: Name='%wZ', Dir='%wZ'\n", NameU, &ParentFcb->PathNameU);
 
     DirContext.LongNameU = *NameU;
+    IsDirectory = BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE);
 
     /* nb of entry needed for long name+normal entry */
     nbSlots = (DirContext.LongNameU.Length / sizeof(WCHAR) + 12) / 13 + 1;
@@ -480,7 +482,7 @@ FATAddEntry(
 
     /* set attributes */
     DirContext.DirEntry.Fat.Attrib = ReqAttr;
-    if (RequestedOptions & FILE_DIRECTORY_FILE)
+    if (IsDirectory)
     {
         DirContext.DirEntry.Fat.Attrib |= FILE_ATTRIBUTE_DIRECTORY;
     }
@@ -534,7 +536,7 @@ FATAddEntry(
         return STATUS_DISK_FULL;
     }
     DirContext.DirIndex = DirContext.StartIndex + nbSlots - 1;
-    if (RequestedOptions & FILE_DIRECTORY_FILE)
+    if (IsDirectory)
     {
         /* If we aren't moving, use next */
         if (MoveContext == NULL)
@@ -653,7 +655,7 @@ FATAddEntry(
     DPRINT("new : entry=%11.11s\n", (*Fcb)->entry.Fat.Filename);
     DPRINT("new : entry=%11.11s\n", DirContext.DirEntry.Fat.Filename);
 
-    if (RequestedOptions & FILE_DIRECTORY_FILE)
+    if (IsDirectory)
     {
         FileOffset.QuadPart = 0;
         _SEH2_TRY
@@ -759,7 +761,7 @@ FATXAddEntry(
 
     /* set attributes */
     DirContext.DirEntry.FatX.Attrib = ReqAttr;
-    if (RequestedOptions & FILE_DIRECTORY_FILE)
+    if (BooleanFlagOn(RequestedOptions, FILE_DIRECTORY_FILE))
     {
         DirContext.DirEntry.FatX.Attrib |= FILE_ATTRIBUTE_DIRECTORY;
     }
@@ -822,7 +824,7 @@ VfatAddEntry(
     IN UCHAR ReqAttr,
     IN PVFAT_MOVE_CONTEXT MoveContext)
 {
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
         return FATXAddEntry(DeviceExt, NameU, Fcb, ParentFcb, RequestedOptions, ReqAttr, MoveContext);
     else
         return FATAddEntry(DeviceExt, NameU, Fcb, ParentFcb, RequestedOptions, ReqAttr, MoveContext);
@@ -925,7 +927,7 @@ FATXDelEntry(
 
     ASSERT(pFcb);
     ASSERT(pFcb->parentFcb);
-    ASSERT(pFcb->Flags & FCB_IS_FATX_ENTRY);
+    ASSERT(BooleanFlagOn(pFcb->Flags, FCB_IS_FATX_ENTRY));
 
     StartIndex = pFcb->startIndex;
 
@@ -981,7 +983,7 @@ VfatDelEntry(
     IN PVFATFCB pFcb,
     OUT PVFAT_MOVE_CONTEXT MoveContext)
 {
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
         return FATXDelEntry(DeviceExt, pFcb, MoveContext);
     else
         return FATDelEntry(DeviceExt, pFcb, MoveContext);
index a1e5fe2..2fd7dcb 100644 (file)
@@ -131,7 +131,7 @@ VfatFastIoQueryBasicInfo(
 
     FsRtlEnterFileSystem();
 
-    if (!(FCB->Flags & FCB_IS_PAGE_FILE))
+    if (!BooleanFlagOn(FCB->Flags, FCB_IS_PAGE_FILE))
     {
         if (!ExAcquireResourceSharedLite(&FCB->MainResource, Wait))
         {
@@ -146,7 +146,7 @@ VfatFastIoQueryBasicInfo(
                                      Buffer,
                                      &BufferLength);
 
-    if (!(FCB->Flags & FCB_IS_PAGE_FILE))
+    if (!BooleanFlagOn(FCB->Flags, FCB_IS_PAGE_FILE))
     {
         ExReleaseResourceLite(&FCB->MainResource);
     }
@@ -192,7 +192,7 @@ VfatFastIoQueryStandardInfo(
 
     FsRtlEnterFileSystem();
 
-    if (!(FCB->Flags & FCB_IS_PAGE_FILE))
+    if (!BooleanFlagOn(FCB->Flags, FCB_IS_PAGE_FILE))
     {
         if (!ExAcquireResourceSharedLite(&FCB->MainResource, Wait))
         {
@@ -205,7 +205,7 @@ VfatFastIoQueryStandardInfo(
                                         Buffer,
                                         &BufferLength);
 
-    if (!(FCB->Flags & FCB_IS_PAGE_FILE))
+    if (!BooleanFlagOn(FCB->Flags, FCB_IS_PAGE_FILE))
     {
         ExReleaseResourceLite(&FCB->MainResource);
     }
@@ -691,7 +691,7 @@ VfatAcquireForCcFlush(
     UNREFERENCED_PARAMETER(DeviceObject);
 
     /* Make sure it is not a volume lock */
-    ASSERT(!(Fcb->Flags & FCB_IS_VOLUME));
+    ASSERT(!BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME));
 
     /* Acquire the resource */
     ExAcquireResourceExclusiveLite(&(Fcb->MainResource), TRUE);
@@ -715,7 +715,7 @@ VfatReleaseForCcFlush(
     UNREFERENCED_PARAMETER(DeviceObject);
 
     /* Make sure it is not a volume lock */
-    ASSERT(!(Fcb->Flags & FCB_IS_VOLUME));
+    ASSERT(!BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME));
 
     /* Release the resource */
     ExReleaseResourceLite(&(Fcb->MainResource));
index 4808d62..efaca6b 100644 (file)
@@ -136,7 +136,7 @@ vfatNewFCB(
     }
     RtlZeroMemory(rcFCB, sizeof(VFATFCB));
     vfatInitFcb(rcFCB, pFileNameU);
-    if (pVCB->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(pVCB->Flags, VCB_IS_FATX))
     {
         rcFCB->Flags |= FCB_IS_FATX_ENTRY;
         rcFCB->Attributes = &rcFCB->entry.FatX.Attrib;
@@ -281,13 +281,6 @@ vfatDestroyFCB(
 }
 
 BOOLEAN
-vfatFCBIsDirectory(
-    PVFATFCB FCB)
-{
-    return ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
-}
-
-BOOLEAN
 vfatFCBIsRoot(
     PVFATFCB FCB)
 {
@@ -408,7 +401,7 @@ vfatInitFCBFromDirEntry(
             }
         }
     }
-    else if (Fcb->Flags & FCB_IS_FATX_ENTRY)
+    else if (BooleanFlagOn(Fcb->Flags, FCB_IS_FATX_ENTRY))
     {
         Size = Fcb->entry.FatX.FileSize;
     }
@@ -418,7 +411,7 @@ vfatInitFCBFromDirEntry(
     }
     Fcb->dirIndex = DirContext->DirIndex;
     Fcb->startIndex = DirContext->StartIndex;
-    if ((Fcb->Flags & FCB_IS_FATX_ENTRY) && !vfatFCBIsRoot(Fcb))
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_FATX_ENTRY) && !vfatFCBIsRoot(Fcb))
     {
         ASSERT(DirContext->DirIndex >= 2 && DirContext->StartIndex >= 2);
         Fcb->dirIndex = DirContext->DirIndex-2;
@@ -460,7 +453,7 @@ vfatSetFCBNewDirName(
     Fcb->DirNameU.Buffer = Fcb->PathNameU.Buffer;
     vfatSplitPathName(&Fcb->PathNameU, &Fcb->DirNameU, &Fcb->LongNameU);
     Fcb->Hash.Hash = vfatNameHash(0, &Fcb->PathNameU);
-    if (pVCB->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(pVCB->Flags, VCB_IS_FATX))
     {
         Fcb->ShortHash.Hash = Fcb->Hash.Hash;
     }
@@ -644,7 +637,7 @@ vfatMakeRootFCB(
     UNICODE_STRING NameU = RTL_CONSTANT_STRING(L"\\");
 
     FCB = vfatNewFCB(pVCB, &NameU);
-    if (FCB->Flags & FCB_IS_FATX_ENTRY)
+    if (BooleanFlagOn(FCB->Flags, FCB_IS_FATX_ENTRY))
     {
         memset(FCB->entry.FatX.Filename, ' ', 42);
         FCB->entry.FatX.FileSize = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
index 6247e3d..60737f8 100644 (file)
@@ -338,7 +338,7 @@ VfatSetDispositionInformation(
         return STATUS_SUCCESS;
     }
 
-    if (*FCB->Attributes & FILE_ATTRIBUTE_READONLY)
+    if (vfatFCBIsReadOnly(FCB))
     {
         return STATUS_CANNOT_DELETE;
     }
@@ -398,7 +398,7 @@ vfatPrepareTargetForRename(
         if (ReplaceIfExists)
         {
             /* If that's a directory or a read-only file, we're not allowed */
-            if (vfatFCBIsDirectory(TargetFcb) || ((*TargetFcb->Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY))
+            if (vfatFCBIsDirectory(TargetFcb) || vfatFCBIsReadOnly(TargetFcb))
             {
                 DPRINT("And this is a readonly file!\n");
                 vfatReleaseFCB(DeviceExt, *ParentFCB);
@@ -791,7 +791,7 @@ VfatSetRenameInformation(
                                         FCB->PathNameU.Length - FCB->LongNameU.Length,
                                         NULL,
                                         NULL,
-                                        ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                        (vfatFCBIsDirectory(FCB) ?
                                         FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                         FILE_ACTION_RENAMED_OLD_NAME,
                                         NULL);
@@ -804,7 +804,7 @@ VfatSetRenameInformation(
                                             FCB->PathNameU.Length - FCB->LongNameU.Length,
                                             NULL,
                                             NULL,
-                                            ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                            (vfatFCBIsDirectory(FCB) ?
                                             FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                             FILE_ACTION_RENAMED_NEW_NAME,
                                             NULL);
@@ -834,7 +834,7 @@ VfatSetRenameInformation(
                                         FCB->PathNameU.Length - FCB->LongNameU.Length,
                                         NULL,
                                         NULL,
-                                        ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                        (vfatFCBIsDirectory(FCB) ?
                                         FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                         (DeletedTarget ? FILE_ACTION_REMOVED : FILE_ACTION_RENAMED_OLD_NAME),
                                         NULL);
@@ -862,7 +862,7 @@ VfatSetRenameInformation(
                                                 FCB->PathNameU.Length - FCB->LongNameU.Length,
                                                 NULL,
                                                 NULL,
-                                                ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                                (vfatFCBIsDirectory(FCB) ?
                                                 FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                                 FILE_ACTION_RENAMED_NEW_NAME,
                                                 NULL);
@@ -905,7 +905,7 @@ VfatSetRenameInformation(
                                     FCB->PathNameU.Length - FCB->LongNameU.Length,
                                     NULL,
                                     NULL,
-                                    ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                    (vfatFCBIsDirectory(FCB) ?
                                     FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                     FILE_ACTION_REMOVED,
                                     NULL);
@@ -933,7 +933,7 @@ VfatSetRenameInformation(
                                             FCB->PathNameU.Length - FCB->LongNameU.Length,
                                             NULL,
                                             NULL,
-                                            ((*FCB->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
+                                            (vfatFCBIsDirectory(FCB) ?
                                             FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
                                             FILE_ACTION_ADDED,
                                             NULL);
index c1ebc89..0a6ffcc 100644 (file)
@@ -33,7 +33,7 @@ VfatFlushFile(
         IoStatus.Status = STATUS_SUCCESS;
     }
 
-    if (Fcb->Flags & FCB_IS_DIRTY)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_DIRTY))
     {
         Status = VfatUpdateEntry(Fcb);
         if (!NT_SUCCESS(Status))
@@ -157,7 +157,7 @@ VfatFlush(
     Fcb = (PVFATFCB)IrpContext->FileObject->FsContext;
     ASSERT(Fcb);
 
-    if (Fcb->Flags & FCB_IS_VOLUME)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME))
     {
         ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
         Status = VfatFlushVolume(IrpContext->DeviceExt, Fcb);
index 06bb80d..5c65973 100644 (file)
@@ -816,8 +816,8 @@ VfatIsVolumeDirty(
     Flags = (PULONG)IrpContext->Irp->AssociatedIrp.SystemBuffer;
     *Flags = 0;
 
-    if ((IrpContext->DeviceExt->VolumeFcb->Flags & VCB_IS_DIRTY) &&
-        !(IrpContext->DeviceExt->VolumeFcb->Flags & VCB_CLEAR_DIRTY))
+    if (BooleanFlagOn(IrpContext->DeviceExt->VolumeFcb->Flags, VCB_IS_DIRTY) &&
+        !BooleanFlagOn(IrpContext->DeviceExt->VolumeFcb->Flags, VCB_CLEAR_DIRTY))
     {
         *Flags |= VOLUME_IS_DIRTY;
     }
@@ -837,7 +837,7 @@ VfatMarkVolumeDirty(
     DPRINT("VfatMarkVolumeDirty(IrpContext %p)\n", IrpContext);
     DeviceExt = IrpContext->DeviceExt;
 
-    if (!(DeviceExt->VolumeFcb->Flags & VCB_IS_DIRTY))
+    if (!BooleanFlagOn(DeviceExt->VolumeFcb->Flags, VCB_IS_DIRTY))
     {
         Status = GetNextCluster(DeviceExt, 1, &eocMark);
         if (NT_SUCCESS(Status))
@@ -870,14 +870,14 @@ VfatLockOrUnlockVolume(
     Fcb = FileObject->FsContext;
 
     /* Only allow locking with the volume open */
-    if (!(Fcb->Flags & FCB_IS_VOLUME))
+    if (!BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME))
     {
         return STATUS_ACCESS_DENIED;
     }
 
     /* Bail out if it's already in the demanded state */
-    if (((DeviceExt->Flags & VCB_VOLUME_LOCKED) && Lock) ||
-        (!(DeviceExt->Flags & VCB_VOLUME_LOCKED) && !Lock))
+    if ((BooleanFlagOn(DeviceExt->Flags, VCB_VOLUME_LOCKED) && Lock) ||
+        (!BooleanFlagOn(DeviceExt->Flags, VCB_VOLUME_LOCKED) && !Lock))
     {
         return STATUS_ACCESS_DENIED;
     }
@@ -921,13 +921,13 @@ VfatDismountVolume(
     /* We HAVE to be locked. Windows also allows dismount with no lock
      * but we're here mainly for 1st stage, so KISS
      */
-    if (!(DeviceExt->Flags & VCB_VOLUME_LOCKED))
+    if (!BooleanFlagOn(DeviceExt->Flags, VCB_VOLUME_LOCKED))
     {
         return STATUS_ACCESS_DENIED;
     }
 
     /* Race condition? */
-    if (DeviceExt->Flags & VCB_DISMOUNT_PENDING)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_DISMOUNT_PENDING))
     {
         return STATUS_VOLUME_DISMOUNTED;
     }
@@ -937,7 +937,7 @@ VfatDismountVolume(
 
     ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
 
-    if (DeviceExt->VolumeFcb->Flags & VCB_CLEAR_DIRTY)
+    if (BooleanFlagOn(DeviceExt->VolumeFcb->Flags, VCB_CLEAR_DIRTY))
     {
         /* Set clean shutdown bit */
         Status = GetNextCluster(DeviceExt, 1, &eocMark);
index a4bfac3..d16507d 100644 (file)
@@ -76,7 +76,7 @@ VfatLockControl(
         return STATUS_INVALID_DEVICE_REQUEST;
     }
 
-    if (*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY)
+    if (vfatFCBIsDirectory(Fcb))
     {
         return STATUS_INVALID_PARAMETER;
     }
@@ -106,6 +106,7 @@ VfatDispatchRequest(
     IN PVFAT_IRP_CONTEXT IrpContext)
 {
     NTSTATUS Status;
+    BOOLEAN QueueIrp, CompleteIrp;
 
     DPRINT("VfatDispatchRequest (IrpContext %p), is called for %s\n", IrpContext,
            IrpContext->MajorFunction >= IRP_MJ_MAXIMUM_FUNCTION ? "????" : MajorFunctionNames[IrpContext->MajorFunction]);
@@ -181,17 +182,20 @@ VfatDispatchRequest(
             Status = STATUS_DRIVER_INTERNAL_ERROR;
     }
 
-    ASSERT((!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
-           ((IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
-           (!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && (IrpContext->Flags & IRPCONTEXT_QUEUE)));
+    QueueIrp = BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_QUEUE);
+    CompleteIrp = BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_COMPLETE);
 
-    if (IrpContext->Flags & IRPCONTEXT_COMPLETE)
+    ASSERT((!CompleteIrp && !QueueIrp) ||
+           (CompleteIrp && !QueueIrp) ||
+           (!CompleteIrp && QueueIrp));
+
+    if (CompleteIrp)
     {
         IrpContext->Irp->IoStatus.Status = Status;
         IoCompleteRequest(IrpContext->Irp, IrpContext->PriorityBoost);
     }
 
-    if (IrpContext->Flags & IRPCONTEXT_QUEUE)
+    if (QueueIrp)
     {
         /* Reset our status flags before queueing the IRP */
         IrpContext->Flags |= IRPCONTEXT_COMPLETE;
index 86adf71..59ce92a 100644 (file)
@@ -155,7 +155,7 @@ VfatReadFileData(
     ASSERT(Length % BytesPerSector == 0);
 
     /* Is this a read of the FAT? */
-    if (Fcb->Flags & FCB_IS_FAT)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_FAT))
     {
         ReadOffset.QuadPart += DeviceExt->FatInfo.FATStart * BytesPerSector;
         Status = VfatReadDiskPartial(IrpContext, &ReadOffset, Length, 0, TRUE);
@@ -172,7 +172,7 @@ VfatReadFileData(
     }
 
     /* Is this a read of the Volume ? */
-    if (Fcb->Flags & FCB_IS_VOLUME)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME))
     {
         Status = VfatReadDiskPartial(IrpContext, &ReadOffset, Length, 0, TRUE);
         if (NT_SUCCESS(Status))
@@ -367,7 +367,7 @@ VfatWriteFileData(
     ASSERT(Length % BytesPerSector == 0);
 
     /* Is this a write of the volume? */
-    if (Fcb->Flags & FCB_IS_VOLUME)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME))
     {
         Status = VfatWriteDiskPartial(IrpContext, &WriteOffset, Length, 0, TRUE);
         if (!NT_SUCCESS(Status))
@@ -378,7 +378,7 @@ VfatWriteFileData(
     }
 
     /* Is this a write to the FAT? */
-    if (Fcb->Flags & FCB_IS_FAT)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_FAT))
     {
         WriteOffset.u.LowPart += DeviceExt->FatInfo.FATStart * BytesPerSector;
         IrpContext->RefCount = 1;
@@ -547,7 +547,7 @@ VfatRead(
     LARGE_INTEGER ByteOffset;
     PVOID Buffer;
     ULONG BytesPerSector;
-    BOOLEAN PagingIo, CanWait, IsVolume;
+    BOOLEAN PagingIo, CanWait, IsVolume, NoCache;
 
     ASSERT(IrpContext);
 
@@ -568,7 +568,7 @@ VfatRead(
     Fcb = IrpContext->FileObject->FsContext;
     ASSERT(Fcb);
 
-    if (Fcb->Flags & FCB_IS_PAGE_FILE)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_PAGE_FILE))
     {
         PFATINFO FatInfo = &IrpContext->DeviceExt->FatInfo;
         IrpContext->Stack->Parameters.Read.ByteOffset.QuadPart += FatInfo->dataStart * FatInfo->BytesPerSector;
@@ -587,9 +587,10 @@ VfatRead(
     PagingIo = BooleanFlagOn(IrpContext->Irp->Flags, IRP_PAGING_IO);
     CanWait = BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT);
     IsVolume = BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME);
+    NoCache = BooleanFlagOn(IrpContext->Irp->Flags, IRP_NOCACHE);
 
     /* fail if file is a directory and no paged read */
-    if (*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY && !PagingIo)
+    if (vfatFCBIsDirectory(Fcb) && !PagingIo)
     {
         Status = STATUS_INVALID_PARAMETER;
         goto ByeBye;
@@ -617,7 +618,7 @@ VfatRead(
        goto ByeBye;
     }
 
-    if (IrpContext->Irp->Flags & (IRP_PAGING_IO | IRP_NOCACHE) || IsVolume)
+    if (NoCache || PagingIo || IsVolume)
     {
         if (ByteOffset.u.LowPart % BytesPerSector != 0 || Length % BytesPerSector != 0)
         {
@@ -660,8 +661,7 @@ VfatRead(
 
     Buffer = VfatGetUserBuffer(IrpContext->Irp, PagingIo);
 
-    if (!(IrpContext->Irp->Flags & (IRP_NOCACHE|IRP_PAGING_IO)) &&
-        !(Fcb->Flags & (FCB_IS_PAGE_FILE|FCB_IS_VOLUME)))
+    if (!PagingIo && !NoCache && !IsVolume)
     {
         // cached read
         Status = STATUS_SUCCESS;
@@ -744,7 +744,7 @@ ByeBye:
     else
     {
         IrpContext->Irp->IoStatus.Status = Status;
-        if (IrpContext->FileObject->Flags & FO_SYNCHRONOUS_IO &&
+        if (BooleanFlagOn(IrpContext->FileObject->Flags, FO_SYNCHRONOUS_IO) &&
             !PagingIo &&
             (NT_SUCCESS(Status) || Status == STATUS_END_OF_FILE))
         {
@@ -771,7 +771,7 @@ VfatWrite(
     ULONG Length = 0;
     PVOID Buffer;
     ULONG BytesPerSector;
-    BOOLEAN PagingIo, CanWait, IsVolume;
+    BOOLEAN PagingIo, CanWait, IsVolume, IsFAT, NoCache;
 
     ASSERT(IrpContext);
 
@@ -792,7 +792,7 @@ VfatWrite(
     Fcb = IrpContext->FileObject->FsContext;
     ASSERT(Fcb);
 
-    if (Fcb->Flags & FCB_IS_PAGE_FILE)
+    if (BooleanFlagOn(Fcb->Flags, FCB_IS_PAGE_FILE))
     {
         PFATINFO FatInfo = &IrpContext->DeviceExt->FatInfo;
         IrpContext->Stack->Parameters.Write.ByteOffset.QuadPart += FatInfo->dataStart * FatInfo->BytesPerSector;
@@ -808,9 +808,11 @@ VfatWrite(
     PagingIo = BooleanFlagOn(IrpContext->Irp->Flags, IRP_PAGING_IO);
     CanWait = BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT);
     IsVolume = BooleanFlagOn(Fcb->Flags, FCB_IS_VOLUME);
+    IsFAT = BooleanFlagOn(Fcb->Flags, FCB_IS_FAT);
+    NoCache = BooleanFlagOn(IrpContext->Irp->Flags, IRP_NOCACHE);
 
     /* fail if file is a directory and no paged read */
-    if (*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY && !PagingIo)
+    if (vfatFCBIsDirectory(Fcb) && !PagingIo)
     {
         Status = STATUS_INVALID_PARAMETER;
         goto ByeBye;
@@ -831,7 +833,7 @@ VfatWrite(
         goto ByeBye;
     }
 
-    if (Fcb->Flags & (FCB_IS_FAT | FCB_IS_VOLUME) ||
+    if (IsFAT || IsVolume ||
         vfatDirEntryGetFirstCluster(IrpContext->DeviceExt, &Fcb->entry) == 1)
     {
         if (ByteOffset.QuadPart + Length > Fcb->RFCB.FileSize.QuadPart)
@@ -842,7 +844,7 @@ VfatWrite(
         }
     }
 
-    if (IrpContext->Irp->Flags & (IRP_PAGING_IO|IRP_NOCACHE) || IsVolume)
+    if (PagingIo || NoCache || IsVolume)
     {
         if (ByteOffset.u.LowPart % BytesPerSector != 0 || Length % BytesPerSector != 0)
         {
@@ -889,7 +891,7 @@ VfatWrite(
         Resource = &Fcb->MainResource;
     }
 
-    if ((Fcb->Flags & FCB_IS_PAGE_FILE) || PagingIo)
+    if (PagingIo)
     {
         if (!ExAcquireResourceSharedLite(Resource, CanWait))
         {
@@ -929,8 +931,7 @@ VfatWrite(
 
     Buffer = VfatGetUserBuffer(IrpContext->Irp, PagingIo);
 
-    if (!(Fcb->Flags & (FCB_IS_FAT|FCB_IS_VOLUME)) &&
-        !PagingIo &&
+    if (!IsFAT && !IsVolume && !PagingIo &&
         ByteOffset.u.LowPart + Length > Fcb->RFCB.FileSize.u.LowPart)
     {
         LARGE_INTEGER AllocationSize;
@@ -943,8 +944,7 @@ VfatWrite(
         }
     }
 
-    if (!(IrpContext->Irp->Flags & (IRP_NOCACHE|IRP_PAGING_IO)) &&
-        !(Fcb->Flags & (FCB_IS_PAGE_FILE|FCB_IS_VOLUME)))
+    if (!NoCache && !PagingIo && !IsVolume)
     {
         // cached write
 
@@ -1008,17 +1008,16 @@ VfatWrite(
     }
 
 Metadata:
-    if (!PagingIo &&
-        !(Fcb->Flags & (FCB_IS_FAT|FCB_IS_VOLUME)))
+    if (!PagingIo && !IsFAT && !IsVolume)
     {
-        if(!(*Fcb->Attributes & FILE_ATTRIBUTE_DIRECTORY))
+        if(!vfatFCBIsDirectory(Fcb))
         {
             LARGE_INTEGER SystemTime;
             ULONG Filter;
 
             // set dates and times
             KeQuerySystemTime (&SystemTime);
-            if (Fcb->Flags & FCB_IS_FATX_ENTRY)
+            if (BooleanFlagOn(Fcb->Flags, FCB_IS_FATX_ENTRY))
             {
                 FsdSystemTimeToDosDateTime(IrpContext->DeviceExt,
                                            &SystemTime, &Fcb->entry.FatX.UpdateDate,
@@ -1069,7 +1068,7 @@ ByeBye:
     else
     {
         IrpContext->Irp->IoStatus.Status = Status;
-        if (IrpContext->FileObject->Flags & FO_SYNCHRONOUS_IO &&
+        if (BooleanFlagOn(IrpContext->FileObject->Flags, FO_SYNCHRONOUS_IO) &&
             !PagingIo && NT_SUCCESS(Status))
         {
             IrpContext->FileObject->CurrentByteOffset.QuadPart =
index 247e6bd..3b475d6 100644 (file)
@@ -516,6 +516,20 @@ VfatMarkIrpContextForQueue(PVFAT_IRP_CONTEXT IrpContext)
     return STATUS_PENDING;
 }
 
+FORCEINLINE
+BOOLEAN
+vfatFCBIsDirectory(PVFATFCB FCB)
+{
+    return BooleanFlagOn(*FCB->Attributes, FILE_ATTRIBUTE_DIRECTORY);
+}
+
+FORCEINLINE
+BOOLEAN
+vfatFCBIsReadOnly(PVFATFCB FCB)
+{
+    return BooleanFlagOn(*FCB->Attributes, FILE_ATTRIBUTE_READONLY);
+}
+
 /* blockdev.c */
 
 NTSTATUS
index 8fccde8..bd421d7 100644 (file)
@@ -59,7 +59,7 @@ FsdGetFsVolumeInformation(
         *BufferLength -= DeviceObject->Vpb->VolumeLabelLength;
     }
 
-    if (DeviceExt->VolumeFcb->Flags & FCB_IS_FATX_ENTRY)
+    if (BooleanFlagOn(DeviceExt->VolumeFcb->Flags, FCB_IS_FATX_ENTRY))
     {
         FsdDosDateTimeToSystemTime(DeviceExt,
                                    DeviceExt->VolumeFcb->entry.FatX.CreationDate,
@@ -260,7 +260,7 @@ FsdSetFsLabelInformation(
         return STATUS_NAME_TOO_LONG;
     }
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
     {
         if (FsLabelInfo->VolumeLabelLength / sizeof(WCHAR) > 42)
             return STATUS_NAME_TOO_LONG;
@@ -289,7 +289,7 @@ FsdSetFsLabelInformation(
     if (!NT_SUCCESS(Status))
         return Status;
 
-    if (DeviceExt->Flags & VCB_IS_FATX)
+    if (BooleanFlagOn(DeviceExt->Flags, VCB_IS_FATX))
     {
         RtlCopyMemory(VolumeLabelDirEntry.FatX.Filename, cString, LabelLen);
         memset(&VolumeLabelDirEntry.FatX.Filename[LabelLen], ' ', 42 - LabelLen);