diff --git a/reactos/lib/fslib/vfatlib/fat12.c b/reactos/lib/fslib/vfatlib/fat12.c index 16dca94701b..050aed8ccff 100644 --- a/reactos/lib/fslib/vfatlib/fat12.c +++ b/reactos/lib/fslib/vfatlib/fat12.c @@ -52,8 +52,9 @@ CalcVolumeSerialNumber(VOID) static NTSTATUS -Fat12WriteBootSector(IN HANDLE FileHandle, - IN PFAT16_BOOT_SECTOR BootSector) +Fat12WriteBootSector (IN HANDLE FileHandle, + IN PFAT16_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -61,9 +62,9 @@ Fat12WriteBootSector(IN HANDLE FileHandle, LARGE_INTEGER FileOffset; /* Allocate buffer for new bootsector */ - NewBootSector = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(), - 0, - SECTORSIZE); + NewBootSector = (PUCHAR)RtlAllocateHeap (RtlGetProcessHeap (), + 0, + SECTORSIZE); if (NewBootSector == NULL) return(STATUS_INSUFFICIENT_RESOURCES); @@ -96,14 +97,17 @@ Fat12WriteBootSector(IN HANDLE FileHandle, /* Free the new boot sector */ RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); + UpdateProgress (Context, 1); + return(Status); } static NTSTATUS -Fat12WriteFAT(IN HANDLE FileHandle, - ULONG SectorOffset, - IN PFAT16_BOOT_SECTOR BootSector) +Fat12WriteFAT (IN HANDLE FileHandle, + IN ULONG SectorOffset, + IN PFAT16_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -146,6 +150,8 @@ Fat12WriteFAT(IN HANDLE FileHandle, return(Status); } + UpdateProgress (Context, 1); + /* Zero the begin of the buffer */ memset(Buffer, 0, 3); @@ -155,12 +161,12 @@ Fat12WriteFAT(IN HANDLE FileHandle, { /* Zero some sectors of the FAT */ FileOffset.QuadPart = (SectorOffset + BootSector->ReservedSectors + i) * BootSector->BytesPerSector; - Size = (ULONG)BootSector->FATSectors - i; - if (Size > Sectors) + if (((ULONG)BootSector->FATSectors - i) <= Sectors) { - Size = Sectors; + Sectors = (ULONG)BootSector->FATSectors - i; } - Size *= BootSector->BytesPerSector; + + Size = Sectors * BootSector->BytesPerSector; Status = NtWriteFile(FileHandle, NULL, NULL, @@ -176,6 +182,8 @@ Fat12WriteFAT(IN HANDLE FileHandle, RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); return(Status); } + + UpdateProgress (Context, Sectors); } /* Free the buffer */ @@ -186,8 +194,9 @@ Fat12WriteFAT(IN HANDLE FileHandle, static NTSTATUS -Fat12WriteRootDirectory(IN HANDLE FileHandle, - IN PFAT16_BOOT_SECTOR BootSector) +Fat12WriteRootDirectory (IN HANDLE FileHandle, + IN PFAT16_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -227,12 +236,12 @@ Fat12WriteRootDirectory(IN HANDLE FileHandle, { /* Zero some sectors of the root directory */ FileOffset.QuadPart = (FirstRootDirSector + i) * BootSector->BytesPerSector; - Size = RootDirSectors - i; - if (Size > Sectors) + + if ((RootDirSectors - i) <= Sectors) { - Size = Sectors; + Sectors = RootDirSectors - i; } - Size *= BootSector->BytesPerSector; + Size = Sectors * BootSector->BytesPerSector; Status = NtWriteFile(FileHandle, NULL, @@ -249,6 +258,7 @@ Fat12WriteRootDirectory(IN HANDLE FileHandle, RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); return(Status); } + UpdateProgress (Context, Sectors); } /* Free the buffer */ @@ -259,13 +269,13 @@ Fat12WriteRootDirectory(IN HANDLE FileHandle, NTSTATUS -Fat12Format (HANDLE FileHandle, - PPARTITION_INFORMATION PartitionInfo, +Fat12Format (HANDLE FileHandle, + PPARTITION_INFORMATION PartitionInfo, PDISK_GEOMETRY DiskGeometry, PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback) + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFORMAT_CONTEXT Context) { FAT16_BOOT_SECTOR BootSector; OEM_STRING VolumeLabel; @@ -331,8 +341,20 @@ Fat12Format (HANDLE FileHandle, DPRINT("BootSector.FATSectors = %hx\n", BootSector.FATSectors); - Status = Fat12WriteBootSector(FileHandle, - &BootSector); + /* Init context data */ + if (QuickFormat) + { + Context->TotalSectorCount = + 1 + (BootSector.FATSectors * 2) + RootDirSectors; + } + else + { + Context->TotalSectorCount = SectorCount; + } + + Status = Fat12WriteBootSector (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat12WriteBootSector() failed with status 0x%.08x\n", Status); @@ -340,9 +362,10 @@ Fat12Format (HANDLE FileHandle, } /* Write first FAT copy */ - Status = Fat12WriteFAT(FileHandle, - 0, - &BootSector); + Status = Fat12WriteFAT (FileHandle, + 0, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat12WriteFAT() failed with status 0x%.08x\n", Status); @@ -350,21 +373,28 @@ Fat12Format (HANDLE FileHandle, } /* Write second FAT copy */ - Status = Fat12WriteFAT(FileHandle, - (ULONG)BootSector.FATSectors, - &BootSector); + Status = Fat12WriteFAT (FileHandle, + (ULONG)BootSector.FATSectors, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat12WriteFAT() failed with status 0x%.08x.\n", Status); return Status; } - Status = Fat12WriteRootDirectory(FileHandle, - &BootSector); + Status = Fat12WriteRootDirectory (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat12WriteRootDirectory() failed with status 0x%.08x\n", Status); } + if (!QuickFormat) + { + /* FIXME: Fill remaining sectors */ + } + return Status; } diff --git a/reactos/lib/fslib/vfatlib/fat16.c b/reactos/lib/fslib/vfatlib/fat16.c index 0867d8a08ce..31b6c5cdd86 100644 --- a/reactos/lib/fslib/vfatlib/fat16.c +++ b/reactos/lib/fslib/vfatlib/fat16.c @@ -52,8 +52,9 @@ CalcVolumeSerialNumber(VOID) static NTSTATUS -Fat16WriteBootSector(IN HANDLE FileHandle, - IN PFAT16_BOOT_SECTOR BootSector) +Fat16WriteBootSector (IN HANDLE FileHandle, + IN PFAT16_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -90,27 +91,29 @@ Fat16WriteBootSector(IN HANDLE FileHandle, { DPRINT("NtWriteFile() failed (Status %lx)\n", Status); RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); - return(Status); + return Status; } + UpdateProgress (Context, 1); + /* Free the new boot sector */ RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); - return(Status); + return Status; } static NTSTATUS -Fat16WriteFAT(IN HANDLE FileHandle, - ULONG SectorOffset, - IN PFAT16_BOOT_SECTOR BootSector) +Fat16WriteFAT (IN HANDLE FileHandle, + IN ULONG SectorOffset, + IN PFAT16_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; PUCHAR Buffer; LARGE_INTEGER FileOffset; ULONG i; - ULONG Size; ULONG Sectors; /* Allocate buffer */ @@ -149,6 +152,8 @@ Fat16WriteFAT(IN HANDLE FileHandle, return(Status); } + UpdateProgress (Context, 1); + /* Zero the begin of the buffer */ memset(Buffer, 0, 4); @@ -158,19 +163,19 @@ Fat16WriteFAT(IN HANDLE FileHandle, { /* Zero some sectors of the FAT */ FileOffset.QuadPart = (SectorOffset + BootSector->ReservedSectors + i) * BootSector->BytesPerSector; - Size = (ULONG)BootSector->FATSectors - i; - if (Size > Sectors) - { - Size = Sectors; - } - Size *= BootSector->BytesPerSector; + + if (((ULONG)BootSector->FATSectors - i) <= Sectors) + { + Sectors = (ULONG)BootSector->FATSectors - i; + } + Status = NtWriteFile(FileHandle, NULL, NULL, NULL, &IoStatusBlock, Buffer, - Size, + Sectors * BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) @@ -179,6 +184,8 @@ Fat16WriteFAT(IN HANDLE FileHandle, RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); return(Status); } + + UpdateProgress (Context, Sectors); } /* Free the buffer */ @@ -189,8 +196,9 @@ Fat16WriteFAT(IN HANDLE FileHandle, static NTSTATUS -Fat16WriteRootDirectory(IN HANDLE FileHandle, - IN PFAT16_BOOT_SECTOR BootSector) +Fat16WriteRootDirectory (IN HANDLE FileHandle, + IN PFAT16_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -199,7 +207,6 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle, ULONG FirstRootDirSector; ULONG RootDirSectors; ULONG Sectors; - ULONG Size; ULONG i; DPRINT("BootSector->ReservedSectors = %hu\n", BootSector->ReservedSectors); @@ -230,12 +237,11 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle, { /* Zero some sectors of the root directory */ FileOffset.QuadPart = (FirstRootDirSector + i) * BootSector->BytesPerSector; - Size = RootDirSectors - i; - if (Size > Sectors) - { - Size = Sectors; - } - Size *= BootSector->BytesPerSector; + + if ((RootDirSectors - i) <= Sectors) + { + Sectors = RootDirSectors - i; + } Status = NtWriteFile(FileHandle, NULL, @@ -243,7 +249,7 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle, NULL, &IoStatusBlock, Buffer, - Size, + Sectors * BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) @@ -252,6 +258,8 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle, RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); return(Status); } + + UpdateProgress (Context, Sectors); } /* Free the buffer */ @@ -262,13 +270,13 @@ Fat16WriteRootDirectory(IN HANDLE FileHandle, NTSTATUS -Fat16Format (HANDLE FileHandle, - PPARTITION_INFORMATION PartitionInfo, +Fat16Format (HANDLE FileHandle, + PPARTITION_INFORMATION PartitionInfo, PDISK_GEOMETRY DiskGeometry, PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback) + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFORMAT_CONTEXT Context) { FAT16_BOOT_SECTOR BootSector; OEM_STRING VolumeLabel; @@ -351,8 +359,20 @@ Fat16Format (HANDLE FileHandle, BootSector.FATSectors = (unsigned short)(TmpVal3 & 0xffff); DPRINT("BootSector.FATSectors = %hu\n", BootSector.FATSectors); - Status = Fat16WriteBootSector(FileHandle, - &BootSector); + /* Init context data */ + if (QuickFormat) + { + Context->TotalSectorCount = + 1 + (BootSector.FATSectors * 2) + RootDirSectors; + } + else + { + Context->TotalSectorCount = SectorCount; + } + + Status = Fat16WriteBootSector (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat16WriteBootSector() failed with status 0x%.08x\n", Status); @@ -360,9 +380,10 @@ Fat16Format (HANDLE FileHandle, } /* Write first FAT copy */ - Status = Fat16WriteFAT(FileHandle, - 0, - &BootSector); + Status = Fat16WriteFAT (FileHandle, + 0, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat16WriteFAT() failed with status 0x%.08x\n", Status); @@ -370,21 +391,28 @@ Fat16Format (HANDLE FileHandle, } /* Write second FAT copy */ - Status = Fat16WriteFAT(FileHandle, - (ULONG)BootSector.FATSectors, - &BootSector); + Status = Fat16WriteFAT (FileHandle, + (ULONG)BootSector.FATSectors, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat16WriteFAT() failed with status 0x%.08x.\n", Status); return Status; } - Status = Fat16WriteRootDirectory(FileHandle, - &BootSector); + Status = Fat16WriteRootDirectory (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat16WriteRootDirectory() failed with status 0x%.08x\n", Status); } + if (!QuickFormat) + { + /* FIXME: Fill remaining sectors */ + } + return Status; } diff --git a/reactos/lib/fslib/vfatlib/fat32.c b/reactos/lib/fslib/vfatlib/fat32.c index e6025de6236..a26a9a7c3ba 100644 --- a/reactos/lib/fslib/vfatlib/fat32.c +++ b/reactos/lib/fslib/vfatlib/fat32.c @@ -52,8 +52,9 @@ CalcVolumeSerialNumber(VOID) static NTSTATUS -Fat32WriteBootSector(IN HANDLE FileHandle, - IN PFAT32_BOOT_SECTOR BootSector) +Fat32WriteBootSector (IN HANDLE FileHandle, + IN PFAT32_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -90,9 +91,11 @@ Fat32WriteBootSector(IN HANDLE FileHandle, { DPRINT("NtWriteFile() failed (Status %lx)\n", Status); RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); - return(Status); + return Status; } + UpdateProgress (Context, 1); + /* Write backup boot sector */ if (BootSector->BootBackup != 0x0000) { @@ -110,20 +113,23 @@ Fat32WriteBootSector(IN HANDLE FileHandle, { DPRINT("NtWriteFile() failed (Status %lx)\n", Status); RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); - return(Status); + return Status; } + + UpdateProgress (Context, 1); } /* Free the new boot sector */ RtlFreeHeap(RtlGetProcessHeap(), 0, NewBootSector); - return(Status); + return Status; } static NTSTATUS -Fat32WriteFsInfo(IN HANDLE FileHandle, - IN PFAT32_BOOT_SECTOR BootSector) +Fat32WriteFsInfo (IN HANDLE FileHandle, + IN PFAT32_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -164,6 +170,8 @@ Fat32WriteFsInfo(IN HANDLE FileHandle, return(Status); } + UpdateProgress (Context, 1); + /* Free the new sector buffer */ RtlFreeHeap(RtlGetProcessHeap(), 0, FsInfo); @@ -172,16 +180,16 @@ Fat32WriteFsInfo(IN HANDLE FileHandle, static NTSTATUS -Fat32WriteFAT(IN HANDLE FileHandle, - ULONG SectorOffset, - IN PFAT32_BOOT_SECTOR BootSector) +Fat32WriteFAT (IN HANDLE FileHandle, + IN ULONG SectorOffset, + IN PFAT32_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; PUCHAR Buffer; LARGE_INTEGER FileOffset; ULONG i; - ULONG Size; ULONG Sectors; /* Allocate buffer */ @@ -228,6 +236,8 @@ Fat32WriteFAT(IN HANDLE FileHandle, return(Status); } + UpdateProgress (Context, 1); + /* Zero the begin of the buffer */ memset(Buffer, 0, 12); @@ -237,19 +247,19 @@ Fat32WriteFAT(IN HANDLE FileHandle, { /* Zero some sectors of the FAT */ FileOffset.QuadPart = (SectorOffset + BootSector->ReservedSectors + i) * BootSector->BytesPerSector; - Size = BootSector->FATSectors32 - i; - if (Size > Sectors) + + if ((BootSector->FATSectors32 - i) <= Sectors) { - Size = Sectors; + Sectors = BootSector->FATSectors32 - i; } - Size *= BootSector->BytesPerSector; + Status = NtWriteFile(FileHandle, NULL, NULL, NULL, &IoStatusBlock, Buffer, - Size, + Sectors * BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) @@ -258,6 +268,8 @@ Fat32WriteFAT(IN HANDLE FileHandle, RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); return(Status); } + + UpdateProgress (Context, Sectors); } /* Free the buffer */ @@ -268,8 +280,9 @@ Fat32WriteFAT(IN HANDLE FileHandle, static NTSTATUS -Fat32WriteRootDirectory(IN HANDLE FileHandle, - IN PFAT32_BOOT_SECTOR BootSector) +Fat32WriteRootDirectory (IN HANDLE FileHandle, + IN PFAT32_BOOT_SECTOR BootSector, + IN OUT PFORMAT_CONTEXT Context) { IO_STATUS_BLOCK IoStatusBlock; NTSTATUS Status; @@ -321,6 +334,8 @@ Fat32WriteRootDirectory(IN HANDLE FileHandle, return(Status); } + UpdateProgress (Context, (ULONG)BootSector->SectorsPerCluster); + /* Free the buffer */ RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); @@ -329,13 +344,13 @@ Fat32WriteRootDirectory(IN HANDLE FileHandle, NTSTATUS -Fat32Format (HANDLE FileHandle, - PPARTITION_INFORMATION PartitionInfo, +Fat32Format (HANDLE FileHandle, + PPARTITION_INFORMATION PartitionInfo, PDISK_GEOMETRY DiskGeometry, PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback) + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFORMAT_CONTEXT Context) { FAT32_BOOT_SECTOR BootSector; OEM_STRING VolumeLabel; @@ -417,16 +432,29 @@ Fat32Format (HANDLE FileHandle, BootSector.FATSectors32 = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2; DPRINT("FATSectors32 = %lu\n", BootSector.FATSectors32); - Status = Fat32WriteBootSector(FileHandle, - &BootSector); + /* Init context data */ + if (QuickFormat) + { + Context->TotalSectorCount = + 2 + (BootSector.FATSectors32 * BootSector.FATCount) + BootSector.SectorsPerCluster; + } + else + { + Context->TotalSectorCount = BootSector.SectorsHuge; + } + + Status = Fat32WriteBootSector (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat32WriteBootSector() failed with status 0x%.08x\n", Status); return Status; } - Status = Fat32WriteFsInfo(FileHandle, - &BootSector); + Status = Fat32WriteFsInfo (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat32WriteFsInfo() failed with status 0x%.08x\n", Status); @@ -434,9 +462,10 @@ Fat32Format (HANDLE FileHandle, } /* Write first FAT copy */ - Status = Fat32WriteFAT(FileHandle, - 0, - &BootSector); + Status = Fat32WriteFAT (FileHandle, + 0, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat32WriteFAT() failed with status 0x%.08x\n", Status); @@ -444,21 +473,30 @@ Fat32Format (HANDLE FileHandle, } /* Write second FAT copy */ - Status = Fat32WriteFAT(FileHandle, - BootSector.FATSectors32, - &BootSector); + Status = Fat32WriteFAT (FileHandle, + BootSector.FATSectors32, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat32WriteFAT() failed with status 0x%.08x.\n", Status); return Status; } - Status = Fat32WriteRootDirectory(FileHandle, - &BootSector); + Status = Fat32WriteRootDirectory (FileHandle, + &BootSector, + Context); if (!NT_SUCCESS(Status)) { DPRINT("Fat32WriteRootDirectory() failed with status 0x%.08x\n", Status); } + if (!QuickFormat) + { + /* FIXME: Fill remaining sectors */ + } + return Status; } + +/* EOF */ diff --git a/reactos/lib/fslib/vfatlib/vfatlib.c b/reactos/lib/fslib/vfatlib/vfatlib.c index d06f85c6bc6..1a05e5e94bb 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.c +++ b/reactos/lib/fslib/vfatlib/vfatlib.c @@ -7,14 +7,15 @@ * REVISIONS: * CSH 05/04-2003 Created */ -#define NDEBUG -#include #define NTOS_MODE_USER #include #include #include #include "vfatlib.h" +#define NDEBUG +#include + NTSTATUS VfatInitialize(VOID) @@ -26,23 +27,29 @@ VfatInitialize(VOID) NTSTATUS -VfatFormat( - PUNICODE_STRING DriveRoot, - DWORD MediaFlag, - PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback) +VfatFormat (PUNICODE_STRING DriveRoot, + ULONG MediaFlag, + PUNICODE_STRING Label, + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFMIFSCALLBACK Callback) { OBJECT_ATTRIBUTES ObjectAttributes; DISK_GEOMETRY DiskGeometry; IO_STATUS_BLOCK Iosb; HANDLE FileHandle; PARTITION_INFORMATION PartitionInfo; + FORMAT_CONTEXT Context; NTSTATUS Status; DPRINT("VfatFormat(DriveRoot '%wZ')\n", DriveRoot); + Context.TotalSectorCount = 0; + Context.CurrentSectorCount = 0; + Context.Callback = Callback; + Context.Success = FALSE; + Context.Percent = 0; + InitializeObjectAttributes(&ObjectAttributes, DriveRoot, 0, @@ -138,6 +145,12 @@ VfatFormat( DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition); DPRINT("RecognizedPartition %d\n", PartitionInfo.RecognizedPartition); + if (Callback != NULL) + { + Context.Percent = 0; + Callback (PROGRESS, 0, (PVOID)&Context.Percent); + } + if (PartitionInfo.PartitionLength.QuadPart < (4200ULL * 1024ULL)) { /* FAT12 (volume is smaller than 4.1MB) */ @@ -147,7 +160,7 @@ VfatFormat( Label, QuickFormat, ClusterSize, - Callback); + &Context); } else if (PartitionInfo.PartitionLength.QuadPart < (512ULL * 1024ULL * 1024ULL)) { @@ -158,7 +171,7 @@ VfatFormat( Label, QuickFormat, ClusterSize, - Callback); + &Context); } else { @@ -169,11 +182,17 @@ VfatFormat( Label, QuickFormat, ClusterSize, - Callback); + &Context); } NtClose(FileHandle); + if (Callback != NULL) + { + Context.Success = (BOOLEAN)(NT_SUCCESS(Status)); + Callback (DONE, 0, (PVOID)&Context.Success); + } + DPRINT("VfatFormat() done. Status 0x%.08x\n", Status); return Status; @@ -187,3 +206,24 @@ VfatCleanup(VOID) return STATUS_SUCCESS; } + + +VOID +UpdateProgress (PFORMAT_CONTEXT Context, + 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); + } +} + +/* EOF */ diff --git a/reactos/lib/fslib/vfatlib/vfatlib.h b/reactos/lib/fslib/vfatlib/vfatlib.h index 02406cf4c6a..fd886684907 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.h +++ b/reactos/lib/fslib/vfatlib/vfatlib.h @@ -87,29 +87,45 @@ typedef struct _FAT32_FSINFO } __attribute__((packed)) FAT32_FSINFO, *PFAT32_FSINFO; -NTSTATUS -Fat12Format (HANDLE FileHandle, - PPARTITION_INFORMATION PartitionInfo, - PDISK_GEOMETRY DiskGeometry, - PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback); +typedef struct _FORMAT_CONTEXT +{ + PFMIFSCALLBACK Callback; + ULONG TotalSectorCount; + ULONG CurrentSectorCount; + BOOLEAN Success; + ULONG Percent; +} FORMAT_CONTEXT, *PFORMAT_CONTEXT; + NTSTATUS -Fat16Format (HANDLE FileHandle, - PPARTITION_INFORMATION PartitionInfo, +Fat12Format (HANDLE FileHandle, + PPARTITION_INFORMATION PartitionInfo, PDISK_GEOMETRY DiskGeometry, PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback); + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFORMAT_CONTEXT Context); NTSTATUS -Fat32Format (HANDLE FileHandle, - PPARTITION_INFORMATION PartitionInfo, +Fat16Format (HANDLE FileHandle, + PPARTITION_INFORMATION PartitionInfo, PDISK_GEOMETRY DiskGeometry, PUNICODE_STRING Label, - BOOL QuickFormat, - DWORD ClusterSize, - PFMIFSCALLBACK Callback); + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFORMAT_CONTEXT Context); + +NTSTATUS +Fat32Format (HANDLE FileHandle, + PPARTITION_INFORMATION PartitionInfo, + PDISK_GEOMETRY DiskGeometry, + PUNICODE_STRING Label, + BOOLEAN QuickFormat, + ULONG ClusterSize, + PFORMAT_CONTEXT Context); + +VOID +UpdateProgress (PFORMAT_CONTEXT Context, + ULONG Increment); + +/* EOF */