Author: ekohl
Date: Sun Jul  6 13:12:28 2014
New Revision: 63693

URL: http://svn.reactos.org/svn/reactos?rev=63693&view=rev
Log:
[VFATLIB]
Add full format (wipe) support to the fat32 code.

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

Modified: trunk/reactos/lib/fslib/vfatlib/fat32.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/fat32.c?rev=63693&r1=63692&r2=63693&view=diff
==============================================================================
--- trunk/reactos/lib/fslib/vfatlib/fat32.c     [iso-8859-1] (original)
+++ trunk/reactos/lib/fslib/vfatlib/fat32.c     [iso-8859-1] Sun Jul  6 
13:12:28 2014
@@ -339,6 +339,87 @@
 
     UpdateProgress(Context, (ULONG)BootSector->SectorsPerCluster);
 
+    /* Free the buffer */
+    RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
+
+    return Status;
+}
+
+
+static
+NTSTATUS
+Fat32WipeSectors(
+    IN HANDLE FileHandle,
+    IN PFAT32_BOOT_SECTOR BootSector,
+    IN OUT PFORMAT_CONTEXT Context)
+{
+    IO_STATUS_BLOCK IoStatusBlock;
+    PUCHAR Buffer;
+    LARGE_INTEGER FileOffset;
+    ULONGLONG Sector;
+    ULONG Length;
+    NTSTATUS Status;
+
+    /* Allocate buffer for the cluster */
+    Buffer = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(),
+                                     HEAP_ZERO_MEMORY,
+                                     BootSector->SectorsPerCluster * 
BootSector->BytesPerSector);
+    if (Buffer == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    Sector = 0;
+    Length = BootSector->SectorsPerCluster * BootSector->BytesPerSector;
+
+    while (Sector + BootSector->SectorsPerCluster < BootSector->SectorsHuge)
+    {
+        FileOffset.QuadPart = Sector * BootSector->BytesPerSector;
+
+        Status = NtWriteFile(FileHandle,
+                             NULL,
+                             NULL,
+                             NULL,
+                             &IoStatusBlock,
+                             Buffer,
+                             Length,
+                             &FileOffset,
+                             NULL);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
+            goto done;
+        }
+
+        UpdateProgress(Context, (ULONG)BootSector->SectorsPerCluster);
+
+        Sector += BootSector->SectorsPerCluster;
+    }
+
+    if (Sector + BootSector->SectorsPerCluster > BootSector->SectorsHuge)
+    {
+        DPRINT("Remaining sectors %lu\n", BootSector->SectorsHuge - Sector);
+
+        FileOffset.QuadPart = Sector * BootSector->BytesPerSector;
+        Length = (BootSector->SectorsHuge - Sector) * 
BootSector->BytesPerSector;
+
+        Status = NtWriteFile(FileHandle,
+                             NULL,
+                             NULL,
+                             NULL,
+                             &IoStatusBlock,
+                             Buffer,
+                             Length,
+                             &FileOffset,
+                             NULL);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
+            goto done;
+        }
+
+        UpdateProgress(Context, BootSector->SectorsHuge - Sector);
+    }
+
+done:
     /* Free the buffer */
     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
 
@@ -407,7 +488,7 @@
     BootSector.RootCluster = 2;
     BootSector.FSInfoSector = 1;
     BootSector.BootBackup = 6;
-    BootSector.Drive = DiskGeometry->MediaType == FixedMedia ? 0x80 : 0x00;
+    BootSector.Drive = (DiskGeometry->MediaType == FixedMedia) ? 0x80 : 0x00;
     BootSector.ExtBootSignature = 0x29;
     BootSector.VolumeID = CalcVolumeSerialNumber ();
     if ((Label == NULL) || (Label->Buffer == NULL))
@@ -436,6 +517,20 @@
     Context->TotalSectorCount =
         2 + (BootSector.FATSectors32 * BootSector.FATCount) + 
BootSector.SectorsPerCluster;
 
+    if (!QuickFormat)
+    {
+        Context->TotalSectorCount += BootSector.SectorsHuge;
+
+        Status = Fat32WipeSectors(FileHandle,
+                                  &BootSector,
+                                  Context);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT("Fat32WipeSectors() failed with status 0x%.08x\n", Status);
+            return Status;
+        }
+    }
+
     Status = Fat32WriteBootSector(FileHandle,
                                   &BootSector,
                                   Context);
@@ -484,11 +579,6 @@
         DPRINT("Fat32WriteRootDirectory() failed with status 0x%.08x\n", 
Status);
     }
 
-    if (!QuickFormat)
-    {
-        /* FIXME: Fill remaining sectors */
-    }
-
     return Status;
 }
 


Reply via email to