[FORMATTING]

Fix indentation. No code changes.

svn path=/trunk/; revision=47764
This commit is contained in:
Eric Kohl 2010-06-12 10:25:18 +00:00
parent 78b0fb4a21
commit 0c8457631d
9 changed files with 1644 additions and 1617 deletions

View file

@ -798,9 +798,9 @@ Ext2TotalBlocks(PEXT2_FILESYS Ext2Sys, ULONG DataBlocks)
}
NTSTATUS NTAPI
Ext2Format(
IN PUNICODE_STRING DriveRoot,
NTSTATUS
NTAPI
Ext2Format(IN PUNICODE_STRING DriveRoot,
IN FMIFS_MEDIA_FLAG MediaFlag,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
@ -1002,9 +1002,9 @@ clean_up:
return Status;
}
NTSTATUS WINAPI
Ext2Chkdsk(
IN PUNICODE_STRING DriveRoot,
NTSTATUS
WINAPI
Ext2Chkdsk(IN PUNICODE_STRING DriveRoot,
IN BOOLEAN FixErrors,
IN BOOLEAN Verbose,
IN BOOLEAN CheckOnlyIfDirty,

View file

@ -11,12 +11,12 @@
#include <debug.h>
NTSTATUS NTAPI
NtfsFormat(PUNICODE_STRING DriveRoot,
FMIFS_MEDIA_FLAG MediaFlag,
PUNICODE_STRING Label,
BOOLEAN QuickFormat,
ULONG ClusterSize,
PFMIFSCALLBACK Callback)
NtfsFormat(IN PUNICODE_STRING DriveRoot,
IN FMIFS_MEDIA_FLAG MediaFlag,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN PFMIFSCALLBACK Callback)
{
UNIMPLEMENTED;
return STATUS_SUCCESS;

View file

@ -14,14 +14,16 @@
#include <debug.h>
static ULONG
GetShiftCount(ULONG Value)
GetShiftCount(IN ULONG Value)
{
ULONG i = 1;
while (Value > 0)
{
i++;
Value /= 2;
}
return i - 2;
}
@ -34,8 +36,8 @@ CalcVolumeSerialNumber(VOID)
ULONG Serial;
PUCHAR Buffer;
NtQuerySystemTime (&SystemTime);
RtlTimeToTimeFields (&SystemTime, &TimeFields);
NtQuerySystemTime(&SystemTime);
RtlTimeToTimeFields(&SystemTime, &TimeFields);
Buffer = (PUCHAR)&Serial;
Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour & 0xFF);
@ -48,7 +50,7 @@ CalcVolumeSerialNumber(VOID)
static NTSTATUS
Fat12WriteBootSector (IN HANDLE FileHandle,
Fat12WriteBootSector(IN HANDLE FileHandle,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -58,11 +60,11 @@ Fat12WriteBootSector (IN HANDLE FileHandle,
LARGE_INTEGER FileOffset;
/* Allocate buffer for new bootsector */
NewBootSector = (PUCHAR)RtlAllocateHeap (RtlGetProcessHeap (),
NewBootSector = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap (),
0,
SECTORSIZE);
if (NewBootSector == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */
memset(NewBootSector, 0, SECTORSIZE);
@ -87,20 +89,20 @@ Fat12WriteBootSector (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
return(Status);
return Status;
}
/* Free the new boot sector */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
return(Status);
return Status;
}
static NTSTATUS
Fat12WriteFAT (IN HANDLE FileHandle,
Fat12WriteFAT(IN HANDLE FileHandle,
IN ULONG SectorOffset,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
@ -118,7 +120,7 @@ Fat12WriteFAT (IN HANDLE FileHandle,
0,
32 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 32 * 1024);
@ -143,10 +145,10 @@ Fat12WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
/* Zero the begin of the buffer */
memset(Buffer, 0, 3);
@ -176,21 +178,21 @@ Fat12WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, Sectors);
UpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
static NTSTATUS
Fat12WriteRootDirectory (IN HANDLE FileHandle,
Fat12WriteRootDirectory(IN HANDLE FileHandle,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -222,7 +224,7 @@ Fat12WriteRootDirectory (IN HANDLE FileHandle,
0,
32 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 32 * 1024);
@ -237,6 +239,7 @@ Fat12WriteRootDirectory (IN HANDLE FileHandle,
{
Sectors = RootDirSectors - i;
}
Size = Sectors * BootSector->BytesPerSector;
Status = NtWriteFile(FileHandle,
@ -252,26 +255,27 @@ Fat12WriteRootDirectory (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, Sectors);
UpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
NTSTATUS
Fat12Format (HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
PUNICODE_STRING Label,
BOOLEAN QuickFormat,
ULONG ClusterSize,
PFORMAT_CONTEXT Context)
Fat12Format(IN HANDLE FileHandle,
IN PPARTITION_INFORMATION PartitionInfo,
IN PDISK_GEOMETRY DiskGeometry,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN OUT PFORMAT_CONTEXT Context)
{
FAT16_BOOT_SECTOR BootSector;
OEM_STRING VolumeLabel;
@ -323,6 +327,7 @@ Fat12Format (HANDLE FileHandle,
VolumeLabel.Length < 11 ? VolumeLabel.Length : 11);
RtlFreeOemString(&VolumeLabel);
}
memcpy(&BootSector.SysType[0], "FAT12 ", 8);
RootDirSectors = ((BootSector.RootEntries * 32) +
@ -341,7 +346,7 @@ Fat12Format (HANDLE FileHandle,
Context->TotalSectorCount =
1 + (BootSector.FATSectors * 2) + RootDirSectors;
Status = Fat12WriteBootSector (FileHandle,
Status = Fat12WriteBootSector(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))
@ -351,7 +356,7 @@ Fat12Format (HANDLE FileHandle,
}
/* Write first FAT copy */
Status = Fat12WriteFAT (FileHandle,
Status = Fat12WriteFAT(FileHandle,
0,
&BootSector,
Context);
@ -362,7 +367,7 @@ Fat12Format (HANDLE FileHandle,
}
/* Write second FAT copy */
Status = Fat12WriteFAT (FileHandle,
Status = Fat12WriteFAT(FileHandle,
(ULONG)BootSector.FATSectors,
&BootSector,
Context);
@ -372,7 +377,7 @@ Fat12Format (HANDLE FileHandle,
return Status;
}
Status = Fat12WriteRootDirectory (FileHandle,
Status = Fat12WriteRootDirectory(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))

View file

@ -14,14 +14,16 @@
#include <debug.h>
static ULONG
GetShiftCount(ULONG Value)
GetShiftCount(IN ULONG Value)
{
ULONG i = 1;
while (Value > 0)
{
i++;
Value /= 2;
}
return i - 2;
}
@ -48,7 +50,7 @@ CalcVolumeSerialNumber(VOID)
static NTSTATUS
Fat16WriteBootSector (IN HANDLE FileHandle,
Fat16WriteBootSector(IN HANDLE FileHandle,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -62,7 +64,7 @@ Fat16WriteBootSector (IN HANDLE FileHandle,
0,
SECTORSIZE);
if (NewBootSector == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */
memset(NewBootSector, 0, SECTORSIZE);
@ -90,7 +92,7 @@ Fat16WriteBootSector (IN HANDLE FileHandle,
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
/* Free the new boot sector */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
@ -100,7 +102,7 @@ Fat16WriteBootSector (IN HANDLE FileHandle,
static NTSTATUS
Fat16WriteFAT (IN HANDLE FileHandle,
Fat16WriteFAT(IN HANDLE FileHandle,
IN ULONG SectorOffset,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
@ -117,7 +119,7 @@ Fat16WriteFAT (IN HANDLE FileHandle,
0,
32 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 32 * 1024);
@ -145,10 +147,10 @@ Fat16WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
/* Zero the begin of the buffer */
memset(Buffer, 0, 4);
@ -178,21 +180,21 @@ Fat16WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, Sectors);
UpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
static NTSTATUS
Fat16WriteRootDirectory (IN HANDLE FileHandle,
Fat16WriteRootDirectory(IN HANDLE FileHandle,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -223,7 +225,7 @@ Fat16WriteRootDirectory (IN HANDLE FileHandle,
0,
32 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 32 * 1024);
@ -252,27 +254,27 @@ Fat16WriteRootDirectory (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, Sectors);
UpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
NTSTATUS
Fat16Format (HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
PUNICODE_STRING Label,
BOOLEAN QuickFormat,
ULONG ClusterSize,
PFORMAT_CONTEXT Context)
Fat16Format(IN HANDLE FileHandle,
IN PPARTITION_INFORMATION PartitionInfo,
IN PDISK_GEOMETRY DiskGeometry,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN OUT PFORMAT_CONTEXT Context)
{
FAT16_BOOT_SECTOR BootSector;
OEM_STRING VolumeLabel;
@ -340,6 +342,7 @@ Fat16Format (HANDLE FileHandle,
VolumeLabel.Length < 11 ? VolumeLabel.Length : 11);
RtlFreeOemString(&VolumeLabel);
}
memcpy(&BootSector.SysType[0], "FAT16 ", 8);
DPRINT("BootSector.SectorsHuge = %lx\n", BootSector.SectorsHuge);
@ -359,7 +362,7 @@ Fat16Format (HANDLE FileHandle,
Context->TotalSectorCount =
1 + (BootSector.FATSectors * 2) + RootDirSectors;
Status = Fat16WriteBootSector (FileHandle,
Status = Fat16WriteBootSector(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))
@ -369,7 +372,7 @@ Fat16Format (HANDLE FileHandle,
}
/* Write first FAT copy */
Status = Fat16WriteFAT (FileHandle,
Status = Fat16WriteFAT(FileHandle,
0,
&BootSector,
Context);
@ -380,7 +383,7 @@ Fat16Format (HANDLE FileHandle,
}
/* Write second FAT copy */
Status = Fat16WriteFAT (FileHandle,
Status = Fat16WriteFAT(FileHandle,
(ULONG)BootSector.FATSectors,
&BootSector,
Context);
@ -390,7 +393,7 @@ Fat16Format (HANDLE FileHandle,
return Status;
}
Status = Fat16WriteRootDirectory (FileHandle,
Status = Fat16WriteRootDirectory(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))

View file

@ -14,14 +14,16 @@
#include <debug.h>
static ULONG
GetShiftCount(ULONG Value)
GetShiftCount(IN ULONG Value)
{
ULONG i = 1;
while (Value > 0)
{
i++;
Value /= 2;
}
return i - 2;
}
@ -48,7 +50,7 @@ CalcVolumeSerialNumber(VOID)
static NTSTATUS
Fat32WriteBootSector (IN HANDLE FileHandle,
Fat32WriteBootSector(IN HANDLE FileHandle,
IN PFAT32_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -62,7 +64,7 @@ Fat32WriteBootSector (IN HANDLE FileHandle,
0,
SECTORSIZE);
if (NewBootSector == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */
memset(NewBootSector, 0, SECTORSIZE);
@ -90,7 +92,7 @@ Fat32WriteBootSector (IN HANDLE FileHandle,
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
/* Write backup boot sector */
if (BootSector->BootBackup != 0x0000)
@ -112,7 +114,7 @@ Fat32WriteBootSector (IN HANDLE FileHandle,
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
}
/* Free the new boot sector */
@ -123,7 +125,7 @@ Fat32WriteBootSector (IN HANDLE FileHandle,
static NTSTATUS
Fat32WriteFsInfo (IN HANDLE FileHandle,
Fat32WriteFsInfo(IN HANDLE FileHandle,
IN PFAT32_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -137,7 +139,7 @@ Fat32WriteFsInfo (IN HANDLE FileHandle,
0,
BootSector->BytesPerSector);
if (FsInfo == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new sector */
memset(FsInfo, 0, BootSector->BytesPerSector);
@ -163,20 +165,20 @@ Fat32WriteFsInfo (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, FsInfo);
return(Status);
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
/* Free the new sector buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, FsInfo);
return(Status);
return Status;
}
static NTSTATUS
Fat32WriteFAT (IN HANDLE FileHandle,
Fat32WriteFAT(IN HANDLE FileHandle,
IN ULONG SectorOffset,
IN PFAT32_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
@ -193,7 +195,7 @@ Fat32WriteFAT (IN HANDLE FileHandle,
0,
64 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 64 * 1024);
@ -203,11 +205,13 @@ Fat32WriteFAT (IN HANDLE FileHandle,
Buffer[1] = 0xff;
Buffer[2] = 0xff;
Buffer[3] = 0x0f;
/* FAT cluster 1 */
Buffer[4] = 0xff; /* Clean shutdown, no disk read/write errors, end-of-cluster (EOC) mark */
Buffer[5] = 0xff;
Buffer[6] = 0xff;
Buffer[7] = 0x0f;
/* FAT cluster 2 */
Buffer[8] = 0xff; /* End of root directory */
Buffer[9] = 0xff;
@ -229,10 +233,10 @@ Fat32WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, 1);
UpdateProgress(Context, 1);
/* Zero the begin of the buffer */
memset(Buffer, 0, 12);
@ -262,21 +266,21 @@ Fat32WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, Sectors);
UpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
static NTSTATUS
Fat32WriteRootDirectory (IN HANDLE FileHandle,
Fat32WriteRootDirectory(IN HANDLE FileHandle,
IN PFAT32_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -292,7 +296,7 @@ Fat32WriteRootDirectory (IN HANDLE FileHandle,
0,
BootSector->SectorsPerCluster * BootSector->BytesPerSector);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, BootSector->SectorsPerCluster * BootSector->BytesPerSector);
@ -327,26 +331,26 @@ Fat32WriteRootDirectory (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
UpdateProgress (Context, (ULONG)BootSector->SectorsPerCluster);
UpdateProgress(Context, (ULONG)BootSector->SectorsPerCluster);
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
NTSTATUS
Fat32Format (HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
PUNICODE_STRING Label,
BOOLEAN QuickFormat,
ULONG ClusterSize,
PFORMAT_CONTEXT Context)
Fat32Format(IN HANDLE FileHandle,
IN PPARTITION_INFORMATION PartitionInfo,
IN PDISK_GEOMETRY DiskGeometry,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN OUT PFORMAT_CONTEXT Context)
{
FAT32_BOOT_SECTOR BootSector;
OEM_STRING VolumeLabel;
@ -416,6 +420,7 @@ Fat32Format (HANDLE FileHandle,
VolumeLabel.Length < 11 ? VolumeLabel.Length : 11);
RtlFreeOemString(&VolumeLabel);
}
memcpy(&BootSector.SysType[0], "FAT32 ", 8);
RootDirSectors = ((BootSector.RootEntries * 32) +
@ -432,7 +437,7 @@ Fat32Format (HANDLE FileHandle,
Context->TotalSectorCount =
2 + (BootSector.FATSectors32 * BootSector.FATCount) + BootSector.SectorsPerCluster;
Status = Fat32WriteBootSector (FileHandle,
Status = Fat32WriteBootSector(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))
@ -441,7 +446,7 @@ Fat32Format (HANDLE FileHandle,
return Status;
}
Status = Fat32WriteFsInfo (FileHandle,
Status = Fat32WriteFsInfo(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))
@ -451,7 +456,7 @@ Fat32Format (HANDLE FileHandle,
}
/* Write first FAT copy */
Status = Fat32WriteFAT (FileHandle,
Status = Fat32WriteFAT(FileHandle,
0,
&BootSector,
Context);
@ -462,7 +467,7 @@ Fat32Format (HANDLE FileHandle,
}
/* Write second FAT copy */
Status = Fat32WriteFAT (FileHandle,
Status = Fat32WriteFAT(FileHandle,
BootSector.FATSectors32,
&BootSector,
Context);
@ -472,7 +477,7 @@ Fat32Format (HANDLE FileHandle,
return Status;
}
Status = Fat32WriteRootDirectory (FileHandle,
Status = Fat32WriteRootDirectory(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))

View file

@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS VFAT filesystem library
* FILE: vfatlib.c
* FILE: lib\fslib\vfatlib\vfatlib.c
* PURPOSE: Main API
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
* REVISIONS:
@ -17,13 +17,14 @@ PVOID FsCheckMemQueue;
ULONG FsCheckFlags;
ULONG FsCheckTotalFiles;
NTSTATUS NTAPI
VfatFormat (PUNICODE_STRING DriveRoot,
FMIFS_MEDIA_FLAG MediaFlag,
PUNICODE_STRING Label,
BOOLEAN QuickFormat,
ULONG ClusterSize,
PFMIFSCALLBACK Callback)
NTSTATUS
NTAPI
VfatFormat(IN PUNICODE_STRING DriveRoot,
IN FMIFS_MEDIA_FLAG MediaFlag,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN PFMIFSCALLBACK Callback)
{
OBJECT_ATTRIBUTES ObjectAttributes;
DISK_GEOMETRY DiskGeometry;
@ -145,7 +146,7 @@ VfatFormat (PUNICODE_STRING DriveRoot,
if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL))
{
/* FAT12 (volume is smaller than 4.1MB) */
Status = Fat12Format (FileHandle,
Status = Fat12Format(FileHandle,
&PartitionInfo,
&DiskGeometry,
Label,
@ -156,7 +157,7 @@ VfatFormat (PUNICODE_STRING DriveRoot,
else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
{
/* FAT16 (volume is smaller than 512MB) */
Status = Fat16Format (FileHandle,
Status = Fat16Format(FileHandle,
&PartitionInfo,
&DiskGeometry,
Label,
@ -167,7 +168,7 @@ VfatFormat (PUNICODE_STRING DriveRoot,
else
{
/* FAT32 (volume is 512MB or larger) */
Status = Fat32Format (FileHandle,
Status = Fat32Format(FileHandle,
&PartitionInfo,
&DiskGeometry,
Label,
@ -191,7 +192,7 @@ VfatFormat (PUNICODE_STRING DriveRoot,
VOID
UpdateProgress (PFORMAT_CONTEXT Context,
UpdateProgress(PFORMAT_CONTEXT Context,
ULONG Increment)
{
ULONG NewPercent;
@ -208,6 +209,7 @@ UpdateProgress (PFORMAT_CONTEXT Context,
}
}
VOID
VfatPrint(PCHAR Format, ...)
{
@ -224,12 +226,14 @@ VfatPrint(PCHAR Format, ...)
TextOut.Output = TextBuf;
/* Do the callback */
if (ChkdskCallback) ChkdskCallback(OUTPUT, 0, &TextOut);
if (ChkdskCallback)
ChkdskCallback(OUTPUT, 0, &TextOut);
}
NTSTATUS WINAPI
VfatChkdsk(
IN PUNICODE_STRING DriveRoot,
NTSTATUS
WINAPI
VfatChkdsk(IN PUNICODE_STRING DriveRoot,
IN BOOLEAN FixErrors,
IN BOOLEAN Verbose,
IN BOOLEAN CheckOnlyIfDirty,
@ -246,7 +250,8 @@ VfatChkdsk(
/* Set parameters */
FsCheckFlags = 0;
if (Verbose) FsCheckFlags |= FSCHECK_VERBOSE;
if (Verbose)
FsCheckFlags |= FSCHECK_VERBOSE;
FsCheckTotalFiles = 0;
@ -263,13 +268,20 @@ VfatChkdsk(
}
read_boot(&fs);
if (verify) VfatPrint("Starting check/repair pass.\n");
while (read_fat(&fs), scan_root(&fs)) qfree(&FsCheckMemQueue);
if (ScanDrive) fix_bad(&fs);
if (verify)
VfatPrint("Starting check/repair pass.\n");
while (read_fat(&fs), scan_root(&fs))
qfree(&FsCheckMemQueue);
if (ScanDrive)
fix_bad(&fs);
if (salvage_files)
reclaim_file(&fs);
else
reclaim_free(&fs);
free_clusters = update_free(&fs);
file_unused();
qfree(&FsCheckMemQueue);

View file

@ -109,7 +109,7 @@ typedef struct _FORMAT_CONTEXT
NTSTATUS
Fat12Format (HANDLE FileHandle,
Fat12Format(HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
PUNICODE_STRING Label,
@ -118,7 +118,7 @@ Fat12Format (HANDLE FileHandle,
PFORMAT_CONTEXT Context);
NTSTATUS
Fat16Format (HANDLE FileHandle,
Fat16Format(HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
PUNICODE_STRING Label,
@ -127,7 +127,7 @@ Fat16Format (HANDLE FileHandle,
PFORMAT_CONTEXT Context);
NTSTATUS
Fat32Format (HANDLE FileHandle,
Fat32Format(HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
PUNICODE_STRING Label,
@ -136,7 +136,7 @@ Fat32Format (HANDLE FileHandle,
PFORMAT_CONTEXT Context);
VOID
UpdateProgress (PFORMAT_CONTEXT Context,
UpdateProgress(PFORMAT_CONTEXT Context,
ULONG Increment);
VOID

View file

@ -12,14 +12,16 @@
#include <debug.h>
static ULONG
GetShiftCount(ULONG Value)
GetShiftCount(IN ULONG Value)
{
ULONG i = 1;
while (Value > 0)
{
i++;
Value /= 2;
}
return i - 2;
}
@ -46,7 +48,7 @@ CalcVolumeSerialNumber(VOID)
static NTSTATUS
FatxWriteBootSector (IN HANDLE FileHandle,
FatxWriteBootSector(IN HANDLE FileHandle,
IN PFATX_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
@ -60,7 +62,7 @@ FatxWriteBootSector (IN HANDLE FileHandle,
0,
sizeof(FATX_BOOT_SECTOR));
if (NewBootSector == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the new bootsector */
memset(NewBootSector, 0, sizeof(FATX_BOOT_SECTOR));
@ -86,7 +88,7 @@ FatxWriteBootSector (IN HANDLE FileHandle,
return Status;
}
VfatxUpdateProgress (Context, 1);
VfatxUpdateProgress(Context, 1);
/* Free the new boot sector */
RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector);
@ -96,7 +98,7 @@ FatxWriteBootSector (IN HANDLE FileHandle,
static NTSTATUS
Fatx16WriteFAT (IN HANDLE FileHandle,
Fatx16WriteFAT(IN HANDLE FileHandle,
IN ULONG SectorOffset,
IN ULONG FATSectors,
IN OUT PFORMAT_CONTEXT Context)
@ -113,7 +115,7 @@ Fatx16WriteFAT (IN HANDLE FileHandle,
0,
32 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 32 * 1024);
@ -141,10 +143,10 @@ Fatx16WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
VfatxUpdateProgress (Context, 1);
VfatxUpdateProgress(Context, 1);
/* Zero the begin of the buffer */
memset(Buffer, 0, 4);
@ -173,20 +175,20 @@ Fatx16WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
VfatxUpdateProgress (Context, Sectors);
VfatxUpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
static NTSTATUS
Fatx32WriteFAT (IN HANDLE FileHandle,
Fatx32WriteFAT(IN HANDLE FileHandle,
IN ULONG SectorOffset,
IN ULONG FATSectors,
IN OUT PFORMAT_CONTEXT Context)
@ -203,7 +205,7 @@ Fatx32WriteFAT (IN HANDLE FileHandle,
0,
64 * 1024);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 64 * 1024);
@ -213,6 +215,7 @@ Fatx32WriteFAT (IN HANDLE FileHandle,
Buffer[1] = 0xff;
Buffer[2] = 0xff;
Buffer[3] = 0x0f;
/* FAT cluster 1 */
Buffer[4] = 0xff; /* Clean shutdown, no disk read/write errors, end-of-cluster (EOC) mark */
Buffer[5] = 0xff;
@ -234,10 +237,10 @@ Fatx32WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
VfatxUpdateProgress (Context, 1);
VfatxUpdateProgress(Context, 1);
/* Zero the begin of the buffer */
memset(Buffer, 0, 8);
@ -267,20 +270,20 @@ Fatx32WriteFAT (IN HANDLE FileHandle,
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
VfatxUpdateProgress (Context, Sectors);
VfatxUpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
static NTSTATUS
FatxWriteRootDirectory (IN HANDLE FileHandle,
FatxWriteRootDirectory(IN HANDLE FileHandle,
IN ULONG FATSectors,
IN OUT PFORMAT_CONTEXT Context)
{
@ -303,7 +306,7 @@ FatxWriteRootDirectory (IN HANDLE FileHandle,
0,
RootDirSectors * 512);
if (Buffer == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0xff, RootDirSectors * 512);
@ -328,23 +331,22 @@ FatxWriteRootDirectory (IN HANDLE FileHandle,
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return(Status);
return Status;
}
NTSTATUS
FatxFormat (HANDLE FileHandle,
PPARTITION_INFORMATION PartitionInfo,
PDISK_GEOMETRY DiskGeometry,
BOOLEAN QuickFormat,
PFORMAT_CONTEXT Context)
FatxFormat(IN HANDLE FileHandle,
IN PPARTITION_INFORMATION PartitionInfo,
IN PDISK_GEOMETRY DiskGeometry,
IN BOOLEAN QuickFormat,
IN OUT PFORMAT_CONTEXT Context)
{
FATX_BOOT_SECTOR BootSector;
ULONGLONG SectorCount;
ULONG ClusterCount;
ULONG RootDirSectors;
ULONG FATSectors;
NTSTATUS Status;
SectorCount = PartitionInfo->PartitionLength.QuadPart >> GetShiftCount(512); /* Use shifting to avoid 64-bit division */
@ -380,7 +382,7 @@ FatxFormat (HANDLE FileHandle,
Context->TotalSectorCount = SectorCount;
}
Status = FatxWriteBootSector (FileHandle,
Status = FatxWriteBootSector(FileHandle,
&BootSector,
Context);
if (!NT_SUCCESS(Status))
@ -392,25 +394,26 @@ FatxFormat (HANDLE FileHandle,
/* Write first FAT copy */
if (ClusterCount > 65525)
{
Status = Fatx32WriteFAT (FileHandle,
Status = Fatx32WriteFAT(FileHandle,
0,
FATSectors,
Context);
}
else
{
Status = Fatx16WriteFAT (FileHandle,
Status = Fatx16WriteFAT(FileHandle,
0,
FATSectors,
Context);
}
if (!NT_SUCCESS(Status))
{
DPRINT("FatxWriteFAT() failed with status 0x%.08x\n", Status);
return Status;
}
Status = FatxWriteRootDirectory (FileHandle,
Status = FatxWriteRootDirectory(FileHandle,
FATSectors,
Context);
if (!NT_SUCCESS(Status))

View file

@ -13,12 +13,12 @@
#include <debug.h>
NTSTATUS NTAPI
VfatxFormat (PUNICODE_STRING DriveRoot,
FMIFS_MEDIA_FLAG MediaFlag,
PUNICODE_STRING Label,
BOOLEAN QuickFormat,
ULONG ClusterSize,
PFMIFSCALLBACK Callback)
VfatxFormat(IN PUNICODE_STRING DriveRoot,
IN FMIFS_MEDIA_FLAG MediaFlag,
IN PUNICODE_STRING Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN PFMIFSCALLBACK Callback)
{
OBJECT_ATTRIBUTES ObjectAttributes;
DISK_GEOMETRY DiskGeometry;
@ -134,10 +134,10 @@ VfatxFormat (PUNICODE_STRING DriveRoot,
if (Callback != NULL)
{
Context.Percent = 0;
Callback (PROGRESS, 0, (PVOID)&Context.Percent);
Callback(PROGRESS, 0, (PVOID)&Context.Percent);
}
Status = FatxFormat (FileHandle,
Status = FatxFormat(FileHandle,
&PartitionInfo,
&DiskGeometry,
QuickFormat,
@ -147,7 +147,7 @@ VfatxFormat (PUNICODE_STRING DriveRoot,
if (Callback != NULL)
{
Context.Success = (BOOLEAN)(NT_SUCCESS(Status));
Callback (DONE, 0, (PVOID)&Context.Success);
Callback(DONE, 0, (PVOID)&Context.Success);
}
DPRINT("VfatxFormat() done. Status 0x%.08x\n", Status);
@ -157,20 +157,19 @@ VfatxFormat (PUNICODE_STRING DriveRoot,
VOID
VfatxUpdateProgress (PFORMAT_CONTEXT Context,
ULONG Increment)
VfatxUpdateProgress(IN PFORMAT_CONTEXT Context,
IN ULONG Increment)
{
ULONG NewPercent;
Context->CurrentSectorCount += (ULONGLONG)Increment;
NewPercent = (Context->CurrentSectorCount * 100ULL) / Context->TotalSectorCount;
if (NewPercent > Context->Percent)
{
Context->Percent = NewPercent;
Context->Callback (PROGRESS, 0, &Context->Percent);
Context->Callback(PROGRESS, 0, &Context->Percent);
}
}