2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS VFAT filesystem library
4 * FILE: lib\fslib\vfatlib\common.c
5 * PURPOSE: Common code for Fat support
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
11 /* INCLUDES *******************************************************************/
18 /* FUNCTIONS ******************************************************************/
21 GetShiftCount(IN ULONG Value
)
35 CalcVolumeSerialNumber(VOID
)
37 LARGE_INTEGER SystemTime
;
38 TIME_FIELDS TimeFields
;
42 NtQuerySystemTime(&SystemTime
);
43 RtlTimeToTimeFields(&SystemTime
, &TimeFields
);
45 Buffer
= (PUCHAR
)&Serial
;
46 Buffer
[0] = (UCHAR
)(TimeFields
.Year
& 0xFF) + (UCHAR
)(TimeFields
.Hour
& 0xFF);
47 Buffer
[1] = (UCHAR
)(TimeFields
.Year
>> 8) + (UCHAR
)(TimeFields
.Minute
& 0xFF);
48 Buffer
[2] = (UCHAR
)(TimeFields
.Month
& 0xFF) + (UCHAR
)(TimeFields
.Second
& 0xFF);
49 Buffer
[3] = (UCHAR
)(TimeFields
.Day
& 0xFF) + (UCHAR
)(TimeFields
.Milliseconds
& 0xFF);
54 /***** Wipe function for FAT12, FAT16 and FAT32 formats *****/
58 IN ULONG TotalSectors
,
59 IN ULONG SectorsPerCluster
,
60 IN ULONG BytesPerSector
,
61 IN OUT PFORMAT_CONTEXT Context
)
63 IO_STATUS_BLOCK IoStatusBlock
;
65 LARGE_INTEGER FileOffset
;
70 Length
= SectorsPerCluster
* BytesPerSector
;
72 /* Allocate buffer for the cluster */
73 Buffer
= (PUCHAR
)RtlAllocateHeap(RtlGetProcessHeap(),
77 return STATUS_INSUFFICIENT_RESOURCES
;
79 /* Wipe all clusters */
81 while (Sector
+ SectorsPerCluster
< TotalSectors
)
83 FileOffset
.QuadPart
= Sector
* BytesPerSector
;
85 Status
= NtWriteFile(FileHandle
,
94 if (!NT_SUCCESS(Status
))
96 DPRINT("NtWriteFile() failed (Status %lx)\n", Status
);
100 UpdateProgress(Context
, SectorsPerCluster
);
102 Sector
+= SectorsPerCluster
;
105 /* Wipe the trailing space behind the last cluster */
106 if (Sector
< TotalSectors
)
108 DPRINT("Remaining sectors %lu\n", TotalSectors
- Sector
);
110 FileOffset
.QuadPart
= Sector
* BytesPerSector
;
111 Length
= (TotalSectors
- Sector
) * BytesPerSector
;
113 Status
= NtWriteFile(FileHandle
,
122 if (!NT_SUCCESS(Status
))
124 DPRINT("NtWriteFile() failed (Status %lx)\n", Status
);
128 UpdateProgress(Context
, TotalSectors
- Sector
);
132 /* Free the buffer */
133 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer
);