[FASTFAT]
authorPierre Schweitzer <pierre@reactos.org>
Thu, 21 Sep 2017 09:45:23 +0000 (09:45 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Thu, 21 Sep 2017 09:45:23 +0000 (09:45 +0000)
Misc fixes:
- Only set file attributes if they changed
- Fail to set attributes if directory attribute is asked for a file
- Perform file attributes setting before dates to allow safe fail

svn path=/trunk/; revision=75917

reactos/drivers/filesystems/fastfat/finfo.c

index 1396430..418e94d 100644 (file)
@@ -165,6 +165,36 @@ VfatSetBasicInformation(
     /* Check volume label bit */
     ASSERT(0 == (*FCB->Attributes & _A_VOLID));
 
+    if (BasicInfo->FileAttributes != 0)
+    {
+        UCHAR Attributes;
+
+        Attributes = (BasicInfo->FileAttributes & (FILE_ATTRIBUTE_ARCHIVE |
+                                                   FILE_ATTRIBUTE_SYSTEM |
+                                                   FILE_ATTRIBUTE_HIDDEN |
+                                                   FILE_ATTRIBUTE_DIRECTORY |
+                                                   FILE_ATTRIBUTE_READONLY));
+
+        if (vfatFCBIsDirectory(FCB))
+        {
+            Attributes |= FILE_ATTRIBUTE_DIRECTORY;
+        }
+        else
+        {
+            if (BooleanFlagOn(BasicInfo->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
+            {
+                DPRINT("Setting directory attribute on a file!\n");
+                return STATUS_INVALID_PARAMETER;
+            }
+        }
+
+        if (Attributes != *FCB->Attributes)
+        {
+            *FCB->Attributes = Attributes;
+            DPRINT("Setting attributes 0x%02x\n", *FCB->Attributes);
+        }
+    }
+
     if (vfatVolumeIsFatX(DeviceExt))
     {
         if (BasicInfo->CreationTime.QuadPart != 0 && BasicInfo->CreationTime.QuadPart != -1)
@@ -218,18 +248,6 @@ VfatSetBasicInformation(
         }
     }
 
-    if (BasicInfo->FileAttributes)
-    {
-        *FCB->Attributes = (unsigned char)((*FCB->Attributes &
-                            (FILE_ATTRIBUTE_DIRECTORY | 0x48)) |
-                            (BasicInfo->FileAttributes &
-                             (FILE_ATTRIBUTE_ARCHIVE |
-                              FILE_ATTRIBUTE_SYSTEM |
-                              FILE_ATTRIBUTE_HIDDEN |
-                              FILE_ATTRIBUTE_READONLY)));
-        DPRINT("Setting attributes 0x%02x\n", *FCB->Attributes);
-    }
-
     VfatUpdateEntry(FCB, vfatVolumeIsFatX(DeviceExt));
 
     return STATUS_SUCCESS;