ReactOS 0.4.16-dev-197-g92996da
common.c
Go to the documentation of this file.
1/*
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)
7 * Eric Kohl
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 */
10
11/* INCLUDES *******************************************************************/
12
13#include "vfatlib.h"
14
15#define NDEBUG
16#include <debug.h>
17
18/* FUNCTIONS ******************************************************************/
19
22{
23 ULONG i = 1;
24
25 while (Value > 0)
26 {
27 i++;
28 Value /= 2;
29 }
30
31 return i - 2;
32}
33
36{
37 LARGE_INTEGER SystemTime;
39 ULONG Serial;
41
42 NtQuerySystemTime(&SystemTime);
43 RtlTimeToTimeFields(&SystemTime, &TimeFields);
44
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);
50
51 return Serial;
52}
53
54/***** Wipe function for FAT12, FAT16 and FAT32 formats *****/
58 IN ULONG TotalSectors,
59 IN ULONG SectorsPerCluster,
60 IN ULONG BytesPerSector,
62{
66 ULONGLONG Sector;
69
70 Length = SectorsPerCluster * BytesPerSector;
71
72 /* Allocate buffer for the cluster */
73 Buffer = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(),
75 Length);
76 if (Buffer == NULL)
78
79 /* Wipe all clusters */
80 Sector = 0;
81 while (Sector + SectorsPerCluster < TotalSectors)
82 {
83 FileOffset.QuadPart = Sector * BytesPerSector;
84
86 NULL,
87 NULL,
88 NULL,
90 Buffer,
91 Length,
93 NULL);
94 if (!NT_SUCCESS(Status))
95 {
96 DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
97 goto done;
98 }
99
100 UpdateProgress(Context, SectorsPerCluster);
101
102 Sector += SectorsPerCluster;
103 }
104
105 /* Wipe the trailing space behind the last cluster */
106 if (Sector < TotalSectors)
107 {
108 DPRINT("Remaining sectors %lu\n", TotalSectors - Sector);
109
110 FileOffset.QuadPart = Sector * BytesPerSector;
111 Length = (TotalSectors - Sector) * BytesPerSector;
112
114 NULL,
115 NULL,
116 NULL,
118 Buffer,
119 Length,
120 &FileOffset,
121 NULL);
122 if (!NT_SUCCESS(Status))
123 {
124 DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
125 goto done;
126 }
127
128 UpdateProgress(Context, TotalSectors - Sector);
129 }
130
131done:
132 /* Free the buffer */
133 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
134 return Status;
135}
136
137/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static PTIME_FIELDS TimeFields
Definition: time.c:104
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:569
ULONG GetShiftCount(IN ULONG Value)
Definition: common.c:21
NTSTATUS FatWipeSectors(IN HANDLE FileHandle, IN ULONG TotalSectors, IN ULONG SectorsPerCluster, IN ULONG BytesPerSector, IN OUT PFORMAT_CONTEXT Context)
Definition: common.c:56
ULONG CalcVolumeSerialNumber(VOID)
Definition: common.c:35
#define DPRINT
Definition: sndvol32.h:73
USHORT Milliseconds
Definition: env_spec_w32.h:717
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID UpdateProgress(PFORMAT_CONTEXT Context, ULONG Increment)
Definition: vfatlib.c:321
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
unsigned char UCHAR
Definition: xmlstorage.h:181