Author: akhaldi
Date: Wed Jan 13 15:40:37 2016
New Revision: 70584
URL:
http://svn.reactos.org/svn/reactos?rev=70584&view=rev
Log:
[0.4.0] * Merge the vfatlib work by Hermès and Eric in revisions 70433 => 70435, 70445
=> 70449, 70576 and 70583.
Added:
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/common.c
- copied, changed from r70435, trunk/reactos/lib/fslib/vfatlib/common.c
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/common.h
- copied, changed from r70435, trunk/reactos/lib/fslib/vfatlib/common.h
Modified:
branches/ros-branch-0_4_0/ (props changed)
branches/ros-branch-0_4_0/reactos/ (props changed)
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/CMakeLists.txt
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat12.c
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat16.c
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat32.c
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.c
branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.h
Propchange: branches/ros-branch-0_4_0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 13 15:40:37 2016
@@ -1 +1 @@
-/trunk:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70436-70437,70443,70464,70470,70480,70497,70499-70501,70507-70510,70512-70513,70523,70527-70529
+/trunk:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70433-70437,70443,70445-70449,70464,70470,70480,70497,70499-70501,70507-70510,70512-70513,70523,70527-70529,70576,70583
Propchange: branches/ros-branch-0_4_0/reactos/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 13 15:40:37 2016
@@ -20,4 +20,4 @@
/branches/usb-bringup:51335,51337,51341-51343,51348,51350,51353,51355,51365-51369,51372,51384-54388,54396-54398,54736-54737,54752-54754,54756-54760,54762,54764-54765,54767-54768,54772,54774-54777,54781,54787,54790-54792,54797-54798,54806,54808,54834-54838,54843,54850,54852,54856,54858-54859
/branches/usb-bringup-trunk:55019-55543,55548-55554,55556-55567
/branches/wlan-bringup:54809-54998
-/trunk/reactos:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70436-70437,70443,70464,70470,70480,70497,70501,70507-70510,70523,70527-70529
+/trunk/reactos:70000-70321,70323-70324,70328-70337,70339-70340,70347,70349,70354-70358,70360,70363,70369,70373,70375-70378,70381,70384-70385,70387-70389,70398,70400,70408,70424,70433-70437,70443,70445-70449,70464,70470,70480,70497,70501,70507-70510,70523,70527-70529,70576,70583
Modified: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/CMakeLists.txt [iso-8859-1]
(original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/CMakeLists.txt [iso-8859-1] Wed
Jan 13 15:40:37 2016
@@ -7,6 +7,7 @@
check/file.c
check/io.c
check/lfn.c
+ common.c
fat12.c
fat16.c
fat32.c
Copied: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/common.c (from r70435,
trunk/reactos/lib/fslib/vfatlib/common.c)
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- trunk/reactos/lib/fslib/vfatlib/common.c [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/common.c [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -50,36 +50,36 @@
return Serial;
}
-/***** Wipe function for FAT12 and FAT16 formats, adapted from FAT32 code *****/
+/***** Wipe function for FAT12, FAT16 and FAT32 formats *****/
NTSTATUS
-Fat1216WipeSectors(
+FatWipeSectors(
IN HANDLE FileHandle,
- IN PFAT16_BOOT_SECTOR BootSector,
+ IN ULONG TotalSectors,
+ IN ULONG SectorsPerCluster,
+ IN ULONG BytesPerSector,
IN OUT PFORMAT_CONTEXT Context)
{
IO_STATUS_BLOCK IoStatusBlock;
PUCHAR Buffer;
LARGE_INTEGER FileOffset;
ULONGLONG Sector;
- ULONG SectorsHuge;
ULONG Length;
NTSTATUS Status;
+
+ Length = SectorsPerCluster * BytesPerSector;
/* Allocate buffer for the cluster */
Buffer = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
- BootSector->SectorsPerCluster *
BootSector->BytesPerSector);
+ Length);
if (Buffer == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
+ /* Wipe all clusters */
Sector = 0;
- Length = BootSector->SectorsPerCluster * BootSector->BytesPerSector;
-
- SectorsHuge = (BootSector->SectorsHuge != 0 ? BootSector->SectorsHuge :
BootSector->Sectors);
-
- while (Sector + BootSector->SectorsPerCluster < SectorsHuge)
+ while (Sector + SectorsPerCluster < TotalSectors)
{
- FileOffset.QuadPart = Sector * BootSector->BytesPerSector;
+ FileOffset.QuadPart = Sector * BytesPerSector;
Status = NtWriteFile(FileHandle,
NULL,
@@ -96,17 +96,18 @@
goto done;
}
- UpdateProgress(Context, (ULONG)BootSector->SectorsPerCluster);
+ UpdateProgress(Context, SectorsPerCluster);
- Sector += BootSector->SectorsPerCluster;
+ Sector += SectorsPerCluster;
}
- if (Sector + BootSector->SectorsPerCluster > SectorsHuge)
+ /* Wipe the trailing space behind the last cluster */
+ if (Sector < TotalSectors)
{
- DPRINT("Remaining sectors %lu\n", SectorsHuge - Sector);
+ DPRINT("Remaining sectors %lu\n", TotalSectors - Sector);
- FileOffset.QuadPart = Sector * BootSector->BytesPerSector;
- Length = (SectorsHuge - Sector) * BootSector->BytesPerSector;
+ FileOffset.QuadPart = Sector * BytesPerSector;
+ Length = (TotalSectors - Sector) * BytesPerSector;
Status = NtWriteFile(FileHandle,
NULL,
@@ -123,13 +124,12 @@
goto done;
}
- UpdateProgress(Context, SectorsHuge - Sector);
+ UpdateProgress(Context, TotalSectors - Sector);
}
done:
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-
return Status;
}
Copied: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/common.h (from r70435,
trunk/reactos/lib/fslib/vfatlib/common.h)
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- trunk/reactos/lib/fslib/vfatlib/common.h [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/common.h [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -14,9 +14,11 @@
ULONG CalcVolumeSerialNumber(VOID);
NTSTATUS
-Fat1216WipeSectors(
+FatWipeSectors(
IN HANDLE FileHandle,
- IN PFAT16_BOOT_SECTOR BootSector,
+ IN ULONG TotalSectors,
+ IN ULONG SectorsPerCluster,
+ IN ULONG BytesPerSector,
IN OUT PFORMAT_CONTEXT Context);
#endif /* _VFATCOMMON_H_ */
Modified: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat12.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat12.c [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat12.c [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -5,49 +5,17 @@
* PURPOSE: Fat12 support
* PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
* Eric Kohl
- * REVISIONS:
- * EK 05/04-2003 Created
*/
+
+/* INCLUDES *******************************************************************/
+
#include "vfatlib.h"
#define NDEBUG
#include <debug.h>
-static ULONG
-GetShiftCount(IN ULONG Value)
-{
- ULONG i = 1;
-
- while (Value > 0)
- {
- i++;
- Value /= 2;
- }
-
- return i - 2;
-}
-
-
-static ULONG
-CalcVolumeSerialNumber(VOID)
-{
- LARGE_INTEGER SystemTime;
- TIME_FIELDS TimeFields;
- ULONG Serial;
- PUCHAR Buffer;
-
- NtQuerySystemTime(&SystemTime);
- RtlTimeToTimeFields(&SystemTime, &TimeFields);
-
- Buffer = (PUCHAR)&Serial;
- Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour &
0xFF);
- Buffer[1] = (UCHAR)(TimeFields.Year >> 8) + (UCHAR)(TimeFields.Minute &
0xFF);
- Buffer[2] = (UCHAR)(TimeFields.Month & 0xFF) + (UCHAR)(TimeFields.Second &
0xFF);
- Buffer[3] = (UCHAR)(TimeFields.Day & 0xFF) + (UCHAR)(TimeFields.Milliseconds
& 0xFF);
-
- return Serial;
-}
-
+
+/* FUNCTIONS ******************************************************************/
static NTSTATUS
Fat12WriteBootSector(IN HANDLE FileHandle,
@@ -67,12 +35,13 @@
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */
- memset(NewBootSector, 0, BootSector->BytesPerSector);
+ RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT16 BPB to new bootsector */
memcpy(&NewBootSector->OEMName[0],
&BootSector->OEMName[0],
- FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
OEMName)); /* FAT16 BPB length (up to (not including) Res2) */
+ FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
OEMName));
+ /* FAT16 BPB length (up to (not including) Res2) */
/* Write the boot sector signature */
NewBootSector->Signature1 = 0xAA550000;
@@ -91,15 +60,14 @@
if (!NT_SUCCESS(Status))
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
- return Status;
- }
-
- /* Free the new boot sector */
+ goto done;
+ }
+
+ UpdateProgress(Context, 1);
+
+done:
+ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
-
- UpdateProgress(Context, 1);
-
return Status;
}
@@ -126,7 +94,7 @@
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
- memset(Buffer, 0, 32 * 1024);
+ RtlZeroMemory(Buffer, 32 * 1024);
/* FAT cluster 0 & 1*/
Buffer[0] = 0xf8; /* Media type */
@@ -147,14 +115,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, 3);
+ RtlZeroMemory(Buffer, 3);
/* Zero the rest of the FAT */
Sectors = 32 * 1024 / BootSector->BytesPerSector;
@@ -180,16 +147,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;
}
@@ -230,7 +196,7 @@
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
- memset(Buffer, 0, 32 * 1024);
+ RtlZeroMemory(Buffer, 32 * 1024);
Sectors = 32 * 1024 / BootSector->BytesPerSector;
for (i = 0; i < RootDirSectors; i += Sectors)
@@ -257,16 +223,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;
}
@@ -309,7 +274,7 @@
DPRINT("SectorCount = %lu\n", SectorCount);
- memset(&BootSector, 0, sizeof(FAT16_BOOT_SECTOR));
+ RtlZeroMemory(&BootSector, sizeof(FAT16_BOOT_SECTOR));
memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
@@ -323,7 +288,7 @@
BootSector.Heads = DiskGeometry->TracksPerCylinder;
BootSector.HiddenSectors = PartitionInfo->HiddenSectors;
BootSector.SectorsHuge = (SectorCount >= 0x10000) ? (unsigned long)SectorCount :
0;
- 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))
@@ -333,7 +298,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);
@@ -357,6 +322,22 @@
Context->TotalSectorCount =
1 + (BootSector.FATSectors * 2) + RootDirSectors;
+ if (!QuickFormat)
+ {
+ Context->TotalSectorCount += SectorCount;
+
+ Status = FatWipeSectors(FileHandle,
+ SectorCount,
+ (ULONG)BootSector.SectorsPerCluster,
+ (ULONG)BootSector.BytesPerSector,
+ Context);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("FatWipeSectors() failed with status 0x%.08x\n", Status);
+ return Status;
+ }
+ }
+
Status = Fat12WriteBootSector(FileHandle,
&BootSector,
Context);
@@ -396,10 +377,5 @@
DPRINT("Fat12WriteRootDirectory() failed with status 0x%.08x\n",
Status);
}
- if (!QuickFormat)
- {
- /* FIXME: Fill remaining sectors */
- }
-
return Status;
}
Modified: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat16.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat16.c [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat16.c [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -5,49 +5,17 @@
* PURPOSE: Fat16 support
* PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
* Eric Kohl
- * REVISIONS:
- * EK 05/04-2003 Created
*/
+
+/* INCLUDES *******************************************************************/
+
#include "vfatlib.h"
#define NDEBUG
#include <debug.h>
-static ULONG
-GetShiftCount(IN ULONG Value)
-{
- ULONG i = 1;
-
- while (Value > 0)
- {
- i++;
- Value /= 2;
- }
-
- return i - 2;
-}
-
-
-static ULONG
-CalcVolumeSerialNumber(VOID)
-{
- LARGE_INTEGER SystemTime;
- TIME_FIELDS TimeFields;
- ULONG Serial;
- PUCHAR Buffer;
-
- NtQuerySystemTime (&SystemTime);
- RtlTimeToTimeFields (&SystemTime, &TimeFields);
-
- Buffer = (PUCHAR)&Serial;
- Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour &
0xFF);
- Buffer[1] = (UCHAR)(TimeFields.Year >> 8) + (UCHAR)(TimeFields.Minute &
0xFF);
- Buffer[2] = (UCHAR)(TimeFields.Month & 0xFF) + (UCHAR)(TimeFields.Second &
0xFF);
- Buffer[3] = (UCHAR)(TimeFields.Day & 0xFF) + (UCHAR)(TimeFields.Milliseconds
& 0xFF);
-
- return Serial;
-}
-
+
+/* FUNCTIONS ******************************************************************/
static NTSTATUS
Fat16WriteBootSector(IN HANDLE FileHandle,
@@ -67,12 +35,13 @@
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */
- memset(NewBootSector, 0, BootSector->BytesPerSector);
+ RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT16 BPB to new bootsector */
memcpy(&NewBootSector->OEMName[0],
&BootSector->OEMName[0],
- FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
OEMName)); /* FAT16 BPB length (up to (not including) Res2) */
+ FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
OEMName));
+ /* FAT16 BPB length (up to (not including) Res2) */
/* Write the boot sector signature */
NewBootSector->Signature1 = 0xAA550000;
@@ -91,15 +60,14 @@
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;
}
@@ -125,7 +93,7 @@
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
- memset(Buffer, 0, 32 * 1024);
+ RtlZeroMemory(Buffer, 32 * 1024);
/* FAT cluster 0 */
Buffer[0] = 0xf8; /* Media type */
@@ -149,14 +117,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, 4);
+ RtlZeroMemory(Buffer, 4);
/* Zero the rest of the FAT */
Sectors = 32 * 1024 / BootSector->BytesPerSector;
@@ -182,16 +149,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;
}
@@ -231,7 +197,7 @@
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
- memset(Buffer, 0, 32 * 1024);
+ RtlZeroMemory(Buffer, 32 * 1024);
Sectors = 32 * 1024 / BootSector->BytesPerSector;
for (i = 0; i < RootDirSectors; i += Sectors)
@@ -256,16 +222,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;
}
@@ -316,7 +281,7 @@
SectorCount = PartitionInfo->PartitionLength.QuadPart >>
GetShiftCount(DiskGeometry->BytesPerSector); /* Use shifting to avoid 64-bit
division */
- memset(&BootSector, 0, sizeof(FAT16_BOOT_SECTOR));
+ RtlZeroMemory(&BootSector, sizeof(FAT16_BOOT_SECTOR));
memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
@@ -330,7 +295,7 @@
BootSector.Heads = DiskGeometry->TracksPerCylinder;
BootSector.HiddenSectors = PartitionInfo->HiddenSectors;
BootSector.SectorsHuge = (SectorCount >= 0x10000) ? (unsigned long)SectorCount :
0;
- 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))
@@ -340,7 +305,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);
@@ -365,6 +330,22 @@
Context->TotalSectorCount =
1 + (BootSector.FATSectors * 2) + RootDirSectors;
+ if (!QuickFormat)
+ {
+ Context->TotalSectorCount += SectorCount;
+
+ Status = FatWipeSectors(FileHandle,
+ SectorCount,
+ (ULONG)BootSector.SectorsPerCluster,
+ (ULONG)BootSector.BytesPerSector,
+ Context);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("FatWipeSectors() failed with status 0x%.08x\n", Status);
+ return Status;
+ }
+ }
+
Status = Fat16WriteBootSector(FileHandle,
&BootSector,
Context);
@@ -404,10 +385,5 @@
DPRINT("Fat16WriteRootDirectory() failed with status 0x%.08x\n",
Status);
}
- if (!QuickFormat)
- {
- /* FIXME: Fill remaining sectors */
- }
-
return Status;
}
Modified: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat32.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat32.c [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/fat32.c [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -5,49 +5,17 @@
* PURPOSE: Fat32 support
* PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
* Eric Kohl
- * REVISIONS:
- * EK 05/04-2003 Created
*/
+
+/* INCLUDES *******************************************************************/
+
#include "vfatlib.h"
#define NDEBUG
#include <debug.h>
-static ULONG
-GetShiftCount(IN ULONG Value)
-{
- ULONG i = 1;
-
- while (Value > 0)
- {
- i++;
- Value /= 2;
- }
-
- return i - 2;
-}
-
-
-static ULONG
-CalcVolumeSerialNumber(VOID)
-{
- LARGE_INTEGER SystemTime;
- TIME_FIELDS TimeFields;
- ULONG Serial;
- PUCHAR Buffer;
-
- NtQuerySystemTime (&SystemTime);
- RtlTimeToTimeFields (&SystemTime, &TimeFields);
-
- Buffer = (PUCHAR)&Serial;
- Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour &
0xFF);
- Buffer[1] = (UCHAR)(TimeFields.Year >> 8) + (UCHAR)(TimeFields.Minute &
0xFF);
- Buffer[2] = (UCHAR)(TimeFields.Month & 0xFF) + (UCHAR)(TimeFields.Second &
0xFF);
- Buffer[3] = (UCHAR)(TimeFields.Day & 0xFF) + (UCHAR)(TimeFields.Milliseconds
& 0xFF);
-
- return Serial;
-}
-
+
+/* FUNCTIONS ******************************************************************/
static NTSTATUS
Fat32WriteBootSector(IN HANDLE FileHandle,
@@ -67,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;
@@ -91,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);
@@ -113,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;
}
@@ -136,6 +103,7 @@
NTSTATUS Status;
PFAT32_FSINFO FsInfo;
LARGE_INTEGER FileOffset;
+ ULONGLONG FirstDataSector;
/* Allocate buffer for new sector */
FsInfo = (PFAT32_FSINFO)RtlAllocateHeap(RtlGetProcessHeap(),
@@ -144,16 +112,19 @@
if (FsInfo == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
- /* Zero the new sector */
- memset(FsInfo, 0, BootSector->BytesPerSector);
-
- FsInfo->LeadSig = 0x41615252;
- FsInfo->StrucSig = 0x61417272;
- FsInfo->FreeCount = 0xffffffff;
- FsInfo->NextFree = 0xffffffff;
- FsInfo->TrailSig = 0xaa550000;
-
- /* Write sector */
+ /* Zero the first FsInfo sector */
+ RtlZeroMemory(FsInfo, BootSector->BytesPerSector);
+
+ FirstDataSector = BootSector->ReservedSectors +
+ (BootSector->FATCount * BootSector->FATSectors32) + 0 /* RootDirSectors
*/;
+
+ FsInfo->LeadSig = FSINFO_SECTOR_BEGIN_SIGNATURE;
+ FsInfo->StrucSig = FSINFO_SIGNATURE;
+ FsInfo->FreeCount = (BootSector->SectorsHuge - FirstDataSector) /
BootSector->SectorsPerCluster - 1;
+ FsInfo->NextFree = 0xffffffff;
+ FsInfo->TrailSig = FSINFO_SECTOR_END_SIGNATURE;
+
+ /* Write the first FsInfo sector */
FileOffset.QuadPart = BootSector->FSInfoSector * BootSector->BytesPerSector;
Status = NtWriteFile(FileHandle,
NULL,
@@ -167,15 +138,84 @@
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 */
+ /* Write backup of the first FsInfo sector */
+ if (BootSector->BootBackup != 0x0000)
+ {
+ /* Reset the free cluster count for the backup */
+ FsInfo->FreeCount = 0xffffffff;
+
+ FileOffset.QuadPart = (ULONGLONG)(((ULONG)BootSector->BootBackup +
(ULONG)BootSector->FSInfoSector) * BootSector->BytesPerSector);
+ Status = NtWriteFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ FsInfo,
+ BootSector->BytesPerSector,
+ &FileOffset,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
+ goto done;
+ }
+
+ UpdateProgress(Context, 1);
+ }
+
+ /* Zero the second FsInfo sector */
+ RtlZeroMemory(FsInfo, BootSector->BytesPerSector);
+ FsInfo->TrailSig = FSINFO_SECTOR_END_SIGNATURE;
+
+ /* Write the second FsInfo sector */
+ FileOffset.QuadPart = (BootSector->FSInfoSector + 1) *
BootSector->BytesPerSector;
+ Status = NtWriteFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ FsInfo,
+ BootSector->BytesPerSector,
+ &FileOffset,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
+ goto done;
+ }
+
+ UpdateProgress(Context, 1);
+
+ /* Write backup of the second FsInfo sector */
+ if (BootSector->BootBackup != 0x0000)
+ {
+ FileOffset.QuadPart = (ULONGLONG)(((ULONG)BootSector->BootBackup +
(ULONG)BootSector->FSInfoSector + 1) * BootSector->BytesPerSector);
+ Status = NtWriteFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ FsInfo,
+ BootSector->BytesPerSector,
+ &FileOffset,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
+ goto done;
+ }
+
+ UpdateProgress(Context, 1);
+ }
+
+done:
+ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, FsInfo);
-
return Status;
}
@@ -201,7 +241,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 */
@@ -235,14 +275,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;
@@ -268,16 +307,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;
}
@@ -302,7 +340,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);
@@ -333,96 +371,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);
-
- /* 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);
-
return Status;
}
@@ -467,7 +423,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;
@@ -490,7 +446,7 @@
BootSector.BootBackup = 6;
BootSector.Drive = (DiskGeometry->MediaType == FixedMedia) ? 0x80 : 0x00;
BootSector.ExtBootSignature = 0x29;
- BootSector.VolumeID = CalcVolumeSerialNumber ();
+ BootSector.VolumeID = CalcVolumeSerialNumber();
if ((Label == NULL) || (Label->Buffer == NULL))
{
memcpy(&BootSector.VolumeLabel[0], "NO NAME ", 11);
@@ -498,7 +454,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);
@@ -521,12 +477,14 @@
{
Context->TotalSectorCount += BootSector.SectorsHuge;
- Status = Fat32WipeSectors(FileHandle,
- &BootSector,
- Context);
+ Status = FatWipeSectors(FileHandle,
+ BootSector.SectorsHuge,
+ (ULONG)BootSector.SectorsPerCluster,
+ (ULONG)BootSector.BytesPerSector,
+ Context);
if (!NT_SUCCESS(Status))
{
- DPRINT("Fat32WipeSectors() failed with status 0x%.08x\n", Status);
+ DPRINT("FatWipeSectors() failed with status 0x%.08x\n", Status);
return Status;
}
}
Modified: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.c [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.c [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -4,13 +4,17 @@
* FILE: lib\fslib\vfatlib\vfatlib.c
* PURPOSE: Main API
* PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- * REVISIONS:
- * CSH 05/04-2003 Created
*/
+
+/* INCLUDES *******************************************************************/
+
#include "vfatlib.h"
#define NDEBUG
#include <debug.h>
+
+
+/* GLOBALS & FUNCTIONS ********************************************************/
PFMIFSCALLBACK ChkdskCallback = NULL;
PVOID FsCheckMemQueue;
@@ -261,7 +265,6 @@
DPRINT1("Failed to umount volume (Status: 0x%x)\n", LockStatus);
}
-
LockStatus = NtFsControlFile(FileHandle,
NULL,
NULL,
@@ -282,7 +285,7 @@
if (Callback != NULL)
{
Context.Success = (BOOLEAN)(NT_SUCCESS(Status));
- Callback (DONE, 0, (PVOID)&Context.Success);
+ Callback(DONE, 0, (PVOID)&Context.Success);
}
DPRINT("VfatFormat() done. Status 0x%.08x\n", Status);
@@ -299,7 +302,6 @@
Context->CurrentSectorCount += (ULONGLONG)Increment;
-
NewPercent = (Context->CurrentSectorCount * 100ULL) /
Context->TotalSectorCount;
if (NewPercent > Context->Percent)
@@ -307,7 +309,7 @@
Context->Percent = NewPercent;
if (Context->Callback != NULL)
{
- Context->Callback (PROGRESS, 0, &Context->Percent);
+ Context->Callback(PROGRESS, 0, &Context->Percent);
}
}
}
@@ -327,6 +329,8 @@
/* Prepare parameters */
TextOut.Lines = 1;
TextOut.Output = TextBuf;
+
+ DPRINT1("VfatPrint -- %s", TextBuf);
/* Do the callback */
if (ChkdskCallback)
@@ -368,7 +372,7 @@
if (CheckOnlyIfDirty && !fs_isdirty())
{
/* No need to check FS */
- return fs_close(FALSE);
+ return (fs_close(FALSE) == 0 ? STATUS_SUCCESS : STATUS_DISK_CORRUPT_ERROR);
}
read_boot(&fs);
@@ -414,7 +418,7 @@
}
VfatPrint("%wZ: %u files, %lu/%lu clusters\n", DriveRoot,
- FsCheckTotalFiles, fs.clusters - free_clusters, fs.clusters );
+ FsCheckTotalFiles, fs.clusters - free_clusters, fs.clusters);
if (FixErrors)
{
@@ -426,7 +430,7 @@
}
/* Close the volume */
- return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+ return (fs_close(FixErrors) == 0 ? STATUS_SUCCESS : STATUS_DISK_CORRUPT_ERROR);
}
/* EOF */
Modified: branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_0/reactos/lib/fs…
==============================================================================
--- branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.h [iso-8859-1] (original)
+++ branches/ros-branch-0_4_0/reactos/lib/fslib/vfatlib/vfatlib.h [iso-8859-1] Wed Jan 13
15:40:37 2016
@@ -57,7 +57,6 @@
unsigned long Signature1; // 508
} FAT16_BOOT_SECTOR, *PFAT16_BOOT_SECTOR;
-
typedef struct _FAT32_BOOT_SECTOR
{
unsigned char magic0; // 0
@@ -105,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;
@@ -113,6 +116,8 @@
BOOLEAN Success;
ULONG Percent;
} FORMAT_CONTEXT, *PFORMAT_CONTEXT;
+
+#include "common.h"
NTSTATUS