Author: hbelusca
Date: Sun Dec 27 19:38:13 2015
New Revision: 70446

URL: http://svn.reactos.org/svn/reactos?rev=70446&view=rev
Log:
[VFATLIB]
- Formatting + RtlZero/FillMemory modifications as addendum to r70445.
- Do not hardcode FSInfo signature values, use instead the same set of macros 
fastfat_new introduces.

Modified:
    trunk/reactos/lib/fslib/vfatlib/fat32.c
    trunk/reactos/lib/fslib/vfatlib/vfatlib.h

Modified: trunk/reactos/lib/fslib/vfatlib/fat32.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/fat32.c?rev=70446&r1=70445&r2=70446&view=diff
==============================================================================
--- trunk/reactos/lib/fslib/vfatlib/fat32.c     [iso-8859-1] (original)
+++ trunk/reactos/lib/fslib/vfatlib/fat32.c     [iso-8859-1] Sun Dec 27 
19:38:13 2015
@@ -35,12 +35,13 @@
         return STATUS_INSUFFICIENT_RESOURCES;
 
     /* Zero the new bootsector */
-    memset(NewBootSector, 0, BootSector->BytesPerSector);
+    RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
 
     /* Copy FAT32 BPB to new bootsector */
     memcpy(&NewBootSector->OEMName[0],
            &BootSector->OEMName[0],
-           FIELD_OFFSET(FAT32_BOOT_SECTOR, Res2) - 
FIELD_OFFSET(FAT32_BOOT_SECTOR, OEMName)); /* FAT32 BPB length (up to (not 
including) Res2) */
+           FIELD_OFFSET(FAT32_BOOT_SECTOR, Res2) - 
FIELD_OFFSET(FAT32_BOOT_SECTOR, OEMName));
+           /* FAT32 BPB length (up to (not including) Res2) */
 
     /* Write the boot sector signature */
     NewBootSector->Signature1 = 0xAA550000;
@@ -59,8 +60,7 @@
     if (!NT_SUCCESS(Status))
     {
         DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
-        return Status;
+        goto done;
     }
 
     UpdateProgress(Context, 1);
@@ -81,16 +81,15 @@
         if (!NT_SUCCESS(Status))
         {
             DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
-            RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
-            return Status;
+            goto done;
         }
 
         UpdateProgress(Context, 1);
     }
 
-    /* Free the new boot sector */
+done:
+    /* Free the buffer */
     RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
-
     return Status;
 }
 
@@ -113,13 +112,13 @@
         return STATUS_INSUFFICIENT_RESOURCES;
 
     /* Zero the new sector */
-    memset(FsInfo, 0, BootSector->BytesPerSector);
-
-    FsInfo->LeadSig = 0x41615252;
-    FsInfo->StrucSig = 0x61417272;
+    RtlZeroMemory(FsInfo, BootSector->BytesPerSector);
+
+    FsInfo->LeadSig   = FSINFO_SECTOR_BEGIN_SIGNATURE;
+    FsInfo->StrucSig  = FSINFO_SIGNATURE;
     FsInfo->FreeCount = 0xffffffff;
-    FsInfo->NextFree = 0xffffffff;
-    FsInfo->TrailSig = 0xaa550000;
+    FsInfo->NextFree  = 0xffffffff;
+    FsInfo->TrailSig  = FSINFO_SECTOR_END_SIGNATURE;
 
     /* Write sector */
     FileOffset.QuadPart = BootSector->FSInfoSector * 
BootSector->BytesPerSector;
@@ -135,15 +134,14 @@
     if (!NT_SUCCESS(Status))
     {
         DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(RtlGetProcessHeap(), 0, FsInfo);
-        return Status;
+        goto done;
     }
 
     UpdateProgress(Context, 1);
 
-    /* Free the new sector buffer */
+done:
+    /* Free the buffer */
     RtlFreeHeap(RtlGetProcessHeap(), 0, FsInfo);
-
     return Status;
 }
 
@@ -169,7 +167,7 @@
         return STATUS_INSUFFICIENT_RESOURCES;
 
     /* Zero the buffer */
-    memset(Buffer, 0, 64 * 1024);
+    RtlZeroMemory(Buffer, 64 * 1024);
 
     /* FAT cluster 0 */
     Buffer[0] = 0xf8; /* Media type */
@@ -203,14 +201,13 @@
     if (!NT_SUCCESS(Status))
     {
         DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-        return Status;
+        goto done;
     }
 
     UpdateProgress(Context, 1);
 
     /* Zero the begin of the buffer */
-    memset(Buffer, 0, 12);
+    RtlZeroMemory(Buffer, 12);
 
     /* Zero the rest of the FAT */
     Sectors = 64 * 1024 / BootSector->BytesPerSector;
@@ -236,16 +233,15 @@
         if (!NT_SUCCESS(Status))
         {
             DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
-            RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-            return Status;
+            goto done;
         }
 
         UpdateProgress(Context, Sectors);
     }
 
+done:
     /* Free the buffer */
     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-
     return Status;
 }
 
@@ -270,7 +266,7 @@
         return STATUS_INSUFFICIENT_RESOURCES;
 
     /* Zero the buffer */
-    memset(Buffer, 0, BootSector->SectorsPerCluster * 
BootSector->BytesPerSector);
+    RtlZeroMemory(Buffer, BootSector->SectorsPerCluster * 
BootSector->BytesPerSector);
 
     DPRINT("BootSector->ReservedSectors = %lu\n", BootSector->ReservedSectors);
     DPRINT("BootSector->FATSectors32 = %lu\n", BootSector->FATSectors32);
@@ -301,15 +297,14 @@
     if (!NT_SUCCESS(Status))
     {
         DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-        return Status;
+        goto done;
     }
 
     UpdateProgress(Context, (ULONG)BootSector->SectorsPerCluster);
 
+done:
     /* Free the buffer */
     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-
     return Status;
 }
 
@@ -390,7 +385,6 @@
 done:
     /* Free the buffer */
     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-
     return Status;
 }
 
@@ -435,7 +429,7 @@
         }
     }
 
-    memset(&BootSector, 0, sizeof(FAT32_BOOT_SECTOR));
+    RtlZeroMemory(&BootSector, sizeof(FAT32_BOOT_SECTOR));
     memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
     BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
     BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
@@ -466,7 +460,7 @@
     else
     {
         RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE);
-        memset(&BootSector.VolumeLabel[0], ' ', 11);
+        RtlFillMemory(&BootSector.VolumeLabel[0], 11, ' ');
         memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer,
                VolumeLabel.Length < 11 ? VolumeLabel.Length : 11);
         RtlFreeOemString(&VolumeLabel);

Modified: trunk/reactos/lib/fslib/vfatlib/vfatlib.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/vfatlib.h?rev=70446&r1=70445&r2=70446&view=diff
==============================================================================
--- trunk/reactos/lib/fslib/vfatlib/vfatlib.h   [iso-8859-1] (original)
+++ trunk/reactos/lib/fslib/vfatlib/vfatlib.h   [iso-8859-1] Sun Dec 27 
19:38:13 2015
@@ -104,6 +104,10 @@
 } FAT32_FSINFO, *PFAT32_FSINFO;
 #include <poppack.h>
 
+#define FSINFO_SECTOR_BEGIN_SIGNATURE   0x41615252  // 'RRaA'
+#define FSINFO_SECTOR_END_SIGNATURE     0xAA550000
+#define FSINFO_SIGNATURE                0x61417272  // 'rrAa'
+
 typedef struct _FORMAT_CONTEXT
 {
     PFMIFSCALLBACK Callback;


Reply via email to