ReactOS  0.4.14-dev-115-g4576127
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;
40  PUCHAR Buffer;
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 }
unsigned char * PUCHAR
Definition: retypes.h:3
Definition: bufpool.h:45
USHORT Milliseconds
Definition: env_spec_w32.h:717
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:417
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
static PTIME_FIELDS TimeFields
Definition: time.c:104

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 {
64  PUCHAR Buffer;
66  ULONGLONG Sector;
67  ULONG Length;
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,
92  &FileOffset,
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,
117  &IoStatusBlock,
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 
131 done:
132  /* Free the buffer */
133  RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
134  return Status;
135 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
HANDLE FileHandle
Definition: stats.c:38
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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)
Status
Definition: gdiplustypes.h:24
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
VOID UpdateProgress(PFORMAT_CONTEXT Context, ULONG Increment)
Definition: vfatlib.c:322

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
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
unsigned int ULONG
Definition: retypes.h:1

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