[VFATLIB]

- Formatting fixes.
- Use RtlZeroMemory/RtlFillMemory instead of memset.

svn path=/trunk/; revision=70445
This commit is contained in:
Hermès Bélusca-Maïto 2015-12-27 19:30:53 +00:00
parent d594928f07
commit c3c0206133
3 changed files with 33 additions and 40 deletions

View file

@ -129,7 +129,6 @@ Fat1216WipeSectors(
done: done:
/* Free the buffer */ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status; return Status;
} }

View file

@ -35,12 +35,13 @@ Fat12WriteBootSector(IN HANDLE FileHandle,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */ /* Zero the new bootsector */
memset(NewBootSector, 0, BootSector->BytesPerSector); RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT16 BPB to new bootsector */ /* Copy FAT16 BPB to new bootsector */
memcpy(&NewBootSector->OEMName[0], memcpy(&NewBootSector->OEMName[0],
&BootSector->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 */ /* Write the boot sector signature */
NewBootSector->Signature1 = 0xAA550000; NewBootSector->Signature1 = 0xAA550000;
@ -59,15 +60,14 @@ Fat12WriteBootSector(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); goto done;
return Status;
} }
/* Free the new boot sector */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
UpdateProgress(Context, 1); UpdateProgress(Context, 1);
done:
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
return Status; return Status;
} }
@ -94,7 +94,7 @@ Fat12WriteFAT(IN HANDLE FileHandle,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */ /* Zero the buffer */
memset(Buffer, 0, 32 * 1024); RtlZeroMemory(Buffer, 32 * 1024);
/* FAT cluster 0 & 1*/ /* FAT cluster 0 & 1*/
Buffer[0] = 0xf8; /* Media type */ Buffer[0] = 0xf8; /* Media type */
@ -115,14 +115,13 @@ Fat12WriteFAT(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); goto done;
return Status;
} }
UpdateProgress(Context, 1); UpdateProgress(Context, 1);
/* Zero the begin of the buffer */ /* Zero the begin of the buffer */
memset(Buffer, 0, 3); RtlZeroMemory(Buffer, 3);
/* Zero the rest of the FAT */ /* Zero the rest of the FAT */
Sectors = 32 * 1024 / BootSector->BytesPerSector; Sectors = 32 * 1024 / BootSector->BytesPerSector;
@ -148,16 +147,15 @@ Fat12WriteFAT(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); goto done;
return Status;
} }
UpdateProgress(Context, Sectors); UpdateProgress(Context, Sectors);
} }
done:
/* Free the buffer */ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status; return Status;
} }
@ -198,7 +196,7 @@ Fat12WriteRootDirectory(IN HANDLE FileHandle,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */ /* Zero the buffer */
memset(Buffer, 0, 32 * 1024); RtlZeroMemory(Buffer, 32 * 1024);
Sectors = 32 * 1024 / BootSector->BytesPerSector; Sectors = 32 * 1024 / BootSector->BytesPerSector;
for (i = 0; i < RootDirSectors; i += Sectors) for (i = 0; i < RootDirSectors; i += Sectors)
@ -225,16 +223,15 @@ Fat12WriteRootDirectory(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); goto done;
return Status;
} }
UpdateProgress(Context, Sectors); UpdateProgress(Context, Sectors);
} }
done:
/* Free the buffer */ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status; return Status;
} }
@ -277,7 +274,7 @@ Fat12Format(IN HANDLE FileHandle,
DPRINT("SectorCount = %lu\n", SectorCount); 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); memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
BootSector.BytesPerSector = DiskGeometry->BytesPerSector; BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector; BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
@ -301,7 +298,7 @@ Fat12Format(IN HANDLE FileHandle,
else else
{ {
RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE); RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE);
memset(&BootSector.VolumeLabel[0], ' ', 11); RtlFillMemory(&BootSector.VolumeLabel[0], 11, ' ');
memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer, memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer,
VolumeLabel.Length < 11 ? VolumeLabel.Length : 11); VolumeLabel.Length < 11 ? VolumeLabel.Length : 11);
RtlFreeOemString(&VolumeLabel); RtlFreeOemString(&VolumeLabel);

View file

@ -35,12 +35,13 @@ Fat16WriteBootSector(IN HANDLE FileHandle,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */ /* Zero the new bootsector */
memset(NewBootSector, 0, BootSector->BytesPerSector); RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT16 BPB to new bootsector */ /* Copy FAT16 BPB to new bootsector */
memcpy(&NewBootSector->OEMName[0], memcpy(&NewBootSector->OEMName[0],
&BootSector->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 */ /* Write the boot sector signature */
NewBootSector->Signature1 = 0xAA550000; NewBootSector->Signature1 = 0xAA550000;
@ -59,15 +60,14 @@ Fat16WriteBootSector(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); goto done;
return Status;
} }
UpdateProgress(Context, 1); UpdateProgress(Context, 1);
/* Free the new boot sector */ done:
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
return Status; return Status;
} }
@ -93,7 +93,7 @@ Fat16WriteFAT(IN HANDLE FileHandle,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */ /* Zero the buffer */
memset(Buffer, 0, 32 * 1024); RtlZeroMemory(Buffer, 32 * 1024);
/* FAT cluster 0 */ /* FAT cluster 0 */
Buffer[0] = 0xf8; /* Media type */ Buffer[0] = 0xf8; /* Media type */
@ -117,14 +117,13 @@ Fat16WriteFAT(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); goto done;
return Status;
} }
UpdateProgress(Context, 1); UpdateProgress(Context, 1);
/* Zero the begin of the buffer */ /* Zero the begin of the buffer */
memset(Buffer, 0, 4); RtlZeroMemory(Buffer, 4);
/* Zero the rest of the FAT */ /* Zero the rest of the FAT */
Sectors = 32 * 1024 / BootSector->BytesPerSector; Sectors = 32 * 1024 / BootSector->BytesPerSector;
@ -150,16 +149,15 @@ Fat16WriteFAT(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); goto done;
return Status;
} }
UpdateProgress(Context, Sectors); UpdateProgress(Context, Sectors);
} }
done:
/* Free the buffer */ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status; return Status;
} }
@ -199,7 +197,7 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle,
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */ /* Zero the buffer */
memset(Buffer, 0, 32 * 1024); RtlZeroMemory(Buffer, 32 * 1024);
Sectors = 32 * 1024 / BootSector->BytesPerSector; Sectors = 32 * 1024 / BootSector->BytesPerSector;
for (i = 0; i < RootDirSectors; i += Sectors) for (i = 0; i < RootDirSectors; i += Sectors)
@ -224,16 +222,15 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtWriteFile() failed (Status %lx)\n", Status); DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); goto done;
return Status;
} }
UpdateProgress(Context, Sectors); UpdateProgress(Context, Sectors);
} }
done:
/* Free the buffer */ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status; return Status;
} }
@ -284,7 +281,7 @@ Fat16Format(IN HANDLE FileHandle,
SectorCount = PartitionInfo->PartitionLength.QuadPart >> SectorCount = PartitionInfo->PartitionLength.QuadPart >>
GetShiftCount(DiskGeometry->BytesPerSector); /* Use shifting to avoid 64-bit division */ 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); memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
BootSector.BytesPerSector = DiskGeometry->BytesPerSector; BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector; BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
@ -308,7 +305,7 @@ Fat16Format(IN HANDLE FileHandle,
else else
{ {
RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE); RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE);
memset(&BootSector.VolumeLabel[0], ' ', 11); RtlFillMemory(&BootSector.VolumeLabel[0], 11, ' ');
memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer, memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer,
VolumeLabel.Length < 11 ? VolumeLabel.Length : 11); VolumeLabel.Length < 11 ? VolumeLabel.Length : 11);
RtlFreeOemString(&VolumeLabel); RtlFreeOemString(&VolumeLabel);