ReactOS 0.4.16-dev-88-ga65b6ae
common.c File Reference
#include "vfatlib.h"
#include <debug.h>
Include dependency graph for common.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

ULONG GetShiftCount (IN ULONG Value)
 
ULONG CalcVolumeSerialNumber (VOID)
 
NTSTATUS FatWipeSectors (IN HANDLE FileHandle, IN ULONG TotalSectors, IN ULONG SectorsPerCluster, IN ULONG BytesPerSector, IN OUT PFORMAT_CONTEXT Context)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file common.c.

Function Documentation

◆ CalcVolumeSerialNumber()

ULONG CalcVolumeSerialNumber ( VOID  )

Definition at line 35 of file common.c.

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}
Definition: bufpool.h:45
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
static PTIME_FIELDS TimeFields
Definition: time.c:104
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:569
USHORT Milliseconds
Definition: env_spec_w32.h:717
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by Fat12Format(), Fat16Format(), and Fat32Format().

◆ FatWipeSectors()

NTSTATUS FatWipeSectors ( IN HANDLE  FileHandle,
IN ULONG  TotalSectors,
IN ULONG  SectorsPerCluster,
IN ULONG  BytesPerSector,
IN OUT PFORMAT_CONTEXT  Context 
)

Definition at line 56 of file common.c.

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}
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
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
Status
Definition: gdiplustypes.h:25
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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
#define DPRINT
Definition: sndvol32.h:73
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID UpdateProgress(PFORMAT_CONTEXT Context, ULONG Increment)
Definition: vfatlib.c:321

Referenced by Fat12Format(), Fat16Format(), and Fat32Format().

◆ GetShiftCount()

ULONG GetShiftCount ( IN ULONG  Value)

Definition at line 21 of file common.c.

22{
23 ULONG i = 1;
24
25 while (Value > 0)
26 {
27 i++;
28 Value /= 2;
29 }
30
31 return i - 2;
32}
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
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by Fat12Format(), Fat16Format(), and Fat32Format().