ReactOS 0.4.17-dev-1190-g4c812f4
misc.c File Reference
#include "diskpart.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

BOOL IsDecString (_In_ PWSTR pszDecString)
 
BOOL IsHexString (_In_ PWSTR pszHexString)
 
WCHAR IsDriveLetter (_In_ PWSTR pszString)
 
BOOL HasPrefix (_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *ppszSuffix)
 
ULONGLONG RoundingDivide (_In_ ULONGLONG Dividend, _In_ ULONGLONG Divisor)
 
PWSTR DuplicateQuotedString (_In_ PWSTR pszInString)
 
PWSTR DuplicateString (_In_ PWSTR pszInString)
 
VOID CreateGUID (_Out_ GUID *pGuid)
 
VOID CreateSignature (_Out_ PDWORD pSignature)
 
VOID PrintGUID (_Out_ PWSTR pszBuffer, _In_ GUID *pGuid)
 
static BYTE CharToByte (WCHAR Char)
 
BOOL StringToGUID (_Out_ GUID *pGuid, _In_ PWSTR pszString)
 
VOID PrintBusType (_Out_ PWSTR pszBuffer, _In_ INT cchBufferMax, _In_ STORAGE_BUS_TYPE BusType)
 

Function Documentation

◆ CharToByte()

static BYTE CharToByte ( WCHAR  Char)
static

Definition at line 226 of file misc.c.

228{
229 if (iswdigit(Char))
230 {
231 return (BYTE)((INT)Char - (INT)'0');
232 }
233 else if (iswalpha(Char))
234 {
235 if (iswupper(Char))
236 return (INT)Char - ((INT)'A' - 10);
237 else
238 return (INT)Char - ((INT)'a' - 10);
239 }
240 return 0;
241}
#define INT
Definition: polytest.cpp:20
#define iswupper(_c)
Definition: ctype.h:665
#define iswdigit(_c)
Definition: ctype.h:667
#define iswalpha(_c)
Definition: ctype.h:664
int32_t INT
Definition: typedefs.h:58
unsigned char BYTE
Definition: xxhash.c:193

Referenced by StringToGUID().

◆ CreateGUID()

VOID CreateGUID ( _Out_ GUID *  pGuid)

Definition at line 170 of file misc.c.

172{
173 RtlGenRandom(pGuid, sizeof(*pGuid));
174 /* Clear the version bits and set the version (4) */
175 pGuid->Data3 &= 0x0fff;
176 pGuid->Data3 |= (4 << 12);
177 /* Set the topmost bits of Data4 (clock_seq_hi_and_reserved) as
178 * specified in RFC 4122, section 4.4.
179 */
180 pGuid->Data4[0] &= 0x3f;
181 pGuid->Data4[0] |= 0x80;
182}
#define RtlGenRandom
Definition: ntsecapi.h:691

Referenced by ConvertGPT(), and InsertGptPartition().

◆ CreateSignature()

VOID CreateSignature ( _Out_ PDWORD  pSignature)

Definition at line 186 of file misc.c.

188{
189 LARGE_INTEGER SystemTime;
192
193 NtQuerySystemTime(&SystemTime);
194 RtlTimeToTimeFields(&SystemTime, &TimeFields);
195
196 Buffer = (PUCHAR)pSignature;
197 Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour & 0xFF);
198 Buffer[1] = (UCHAR)(TimeFields.Year >> 8) + (UCHAR)(TimeFields.Minute & 0xFF);
199 Buffer[2] = (UCHAR)(TimeFields.Month & 0xFF) + (UCHAR)(TimeFields.Second & 0xFF);
200 Buffer[3] = (UCHAR)(TimeFields.Day & 0xFF) + (UCHAR)(TimeFields.Milliseconds & 0xFF);
201}
Definition: bufpool.h:45
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
static PTIME_FIELDS TimeFields
Definition: time.c:36
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:563
USHORT Milliseconds
Definition: env_spec_w32.h:717
unsigned char UCHAR
Definition: typedefs.h:53
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by ConvertMBR(), CreateExtendedPartition(), and CreatePrimaryPartition().

◆ DuplicateQuotedString()

PWSTR DuplicateQuotedString ( _In_ PWSTR  pszInString)

Definition at line 102 of file misc.c.

104{
105 PWSTR pszOutString = NULL;
106 PWSTR pStart, pEnd;
107 INT nLength;
108
109 if ((pszInString == NULL) || (pszInString[0] == UNICODE_NULL))
110 return NULL;
111
112 if (pszInString[0] == L'"')
113 {
114 if (pszInString[1] == UNICODE_NULL)
115 return NULL;
116
117 pStart = &pszInString[1];
118 pEnd = wcschr(pStart, '"');
119 if (pEnd == NULL)
120 {
121 nLength = wcslen(pStart);
122 }
123 else
124 {
125 nLength = (pEnd - pStart);
126 }
127 }
128 else
129 {
130 pStart = pszInString;
131 nLength = wcslen(pStart);
132 }
133
134 pszOutString = RtlAllocateHeap(RtlGetProcessHeap(),
136 (nLength + 1) * sizeof(WCHAR));
137 if (pszOutString == NULL)
138 return NULL;
139
140 wcsncpy(pszOutString, pStart, nLength);
141
142 return pszOutString;
143}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
#define NULL
Definition: types.h:112
#define wcschr
Definition: compat.h:17
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
#define L(x)
Definition: resources.c:13
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
wcsncpy
uint16_t * PWSTR
Definition: typedefs.h:56
WINBASEAPI _In_ DWORD nLength
Definition: wincon.h:682

◆ DuplicateString()

PWSTR DuplicateString ( _In_ PWSTR  pszInString)

Definition at line 147 of file misc.c.

149{
150 PWSTR pszOutString = NULL;
151 INT nLength;
152
153 if ((pszInString == NULL) || (pszInString[0] == UNICODE_NULL))
154 return NULL;
155
156 nLength = wcslen(pszInString);
157 pszOutString = RtlAllocateHeap(RtlGetProcessHeap(),
159 (nLength + 1) * sizeof(WCHAR));
160 if (pszOutString == NULL)
161 return NULL;
162
163 wcscpy(pszOutString, pszInString);
164
165 return pszOutString;
166}
wcscpy

◆ HasPrefix()

BOOL HasPrefix ( _In_ PWSTR  pszString,
_In_ PWSTR  pszPrefix,
_Out_opt_ PWSTR *  ppszSuffix 
)

Definition at line 76 of file misc.c.

80{
81 INT nPrefixLength, ret;
82
83 nPrefixLength = wcslen(pszPrefix);
84 ret = _wcsnicmp(pszString, pszPrefix, nPrefixLength);
85 if ((ret == 0) && (ppszSuffix != NULL))
86 *ppszSuffix = &pszString[nPrefixLength];
87
88 return (ret == 0);
89}
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:200
return ret
Definition: mutex.c:147

Referenced by AcpiExGetNameString(), assign_main(), CreateEfiPartition(), CreateExtendedPartition(), CreateLogicalPartition(), CreateMsrPartition(), CreatePrimaryPartition(), format_main(), gpt_main(), remove_main(), setid_main(), and UniqueIdDisk().

◆ IsDecString()

BOOL IsDecString ( _In_ PWSTR  pszDecString)

Definition at line 14 of file misc.c.

16{
17 PWSTR ptr;
18
19 if ((pszDecString == NULL) || (*pszDecString == UNICODE_NULL))
20 return FALSE;
21
22 ptr = pszDecString;
23 while (*ptr != UNICODE_NULL)
24 {
25 if (!iswdigit(*ptr))
26 return FALSE;
27
28 ptr++;
29 }
30
31 return TRUE;
32}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static PVOID ptr
Definition: dispmode.c:27

Referenced by SelectDisk(), SelectPartition(), and SelectVolume().

◆ IsDriveLetter()

WCHAR IsDriveLetter ( _In_ PWSTR  pszString)

Definition at line 57 of file misc.c.

59{
61
62 nLength = wcslen(pszString);
63 if ((nLength == 0) || (nLength > 2))
64 return UNICODE_NULL;
65
66 if (!iswalpha(pszString[0]))
67 return UNICODE_NULL;
68
69 if ((nLength > 1) && (pszString[1] != L':'))
70 return UNICODE_NULL;
71
72 return pszString[0];
73}

Referenced by DeleteDriveLetterRoutine(), HasDriveLetter(), MountMgrCreatePointWorker(), MountMgrDeletePoints(), MountMgrDeletePointsDbOnly(), MountMgrMountedDeviceArrival(), MountMgrNextDriveLetterWorker(), and SelectVolume().

◆ IsHexString()

BOOL IsHexString ( _In_ PWSTR  pszHexString)

Definition at line 36 of file misc.c.

38{
39 PWSTR ptr;
40
41 if ((pszHexString == NULL) || (*pszHexString == UNICODE_NULL))
42 return FALSE;
43
44 ptr = pszHexString;
45 while (*ptr != UNICODE_NULL)
46 {
47 if (!iswxdigit(*ptr))
48 return FALSE;
49
50 ptr++;
51 }
52
53 return TRUE;
54}
#define iswxdigit(_c)
Definition: ctype.h:668

Referenced by UniqueIdDisk().

◆ PrintBusType()

VOID PrintBusType ( _Out_ PWSTR  pszBuffer,
_In_ INT  cchBufferMax,
_In_ STORAGE_BUS_TYPE  BusType 
)

Definition at line 313 of file misc.c.

317{
318 if (BusType <= BusTypeMax)
321 pszBuffer,
322 cchBufferMax);
323 else
326 pszBuffer,
327 cchBufferMax);
328}
#define IDS_BUSTYPE_OTHER
Definition: resource.h:263
#define IDS_BUSTYPE_UNKNOWN
Definition: resource.h:242
@ BusTypeMax
Definition: ntddstor.h:454
#define LoadStringW
Definition: utils.h:64
#define GetModuleHandle
Definition: winbase.h:3550
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:159

Referenced by DetailDisk().

◆ PrintGUID()

VOID PrintGUID ( _Out_ PWSTR  pszBuffer,
_In_ GUID *  pGuid 
)

Definition at line 205 of file misc.c.

208{
209 _swprintf(pszBuffer,
210 L"%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
211 pGuid->Data1,
212 pGuid->Data2,
213 pGuid->Data3,
214 pGuid->Data4[0],
215 pGuid->Data4[1],
216 pGuid->Data4[2],
217 pGuid->Data4[3],
218 pGuid->Data4[4],
219 pGuid->Data4[5],
220 pGuid->Data4[6],
221 pGuid->Data4[7]);
222}
#define _swprintf(buf, format,...)
Definition: sprintf.c:56

Referenced by DetailDisk(), DetailPartition(), and UniqueIdDisk().

◆ RoundingDivide()

ULONGLONG RoundingDivide ( _In_ ULONGLONG  Dividend,
_In_ ULONGLONG  Divisor 
)

Definition at line 93 of file misc.c.

96{
97 return (Dividend + Divisor / 2) / Divisor;
98}
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3068

◆ StringToGUID()

BOOL StringToGUID ( _Out_ GUID *  pGuid,
_In_ PWSTR  pszString 
)

Definition at line 245 of file misc.c.

248{
249 INT i;
250
251 if (pszString == NULL)
252 return FALSE;
253
254 pGuid->Data1 = 0;
255 for (i = 0; i < 8; i++)
256 {
257 if (!iswxdigit(pszString[i]))
258 return FALSE;
259
260 pGuid->Data1 = (pGuid->Data1 << 4) | CharToByte(pszString[i]);
261 }
262
263 if (pszString[8] != L'-')
264 return FALSE;
265
266 pGuid->Data2 = 0;
267 for (i = 9; i < 13; i++)
268 {
269 if (!iswxdigit(pszString[i]))
270 return FALSE;
271
272 pGuid->Data2 = (pGuid->Data2 << 4) | CharToByte(pszString[i]);
273 }
274
275 if (pszString[13] != L'-')
276 return FALSE;
277
278 pGuid->Data3 = 0;
279 for (i = 14; i < 18; i++)
280 {
281 if (!iswxdigit(pszString[i]))
282 return FALSE;
283
284 pGuid->Data3 = (pGuid->Data3 << 4) | CharToByte(pszString[i]);
285 }
286
287 if (pszString[18] != L'-')
288 return FALSE;
289
290 for (i = 19; i < 36; i += 2)
291 {
292 if (i == 23)
293 {
294 if (pszString[i] != L'-')
295 return FALSE;
296 i++;
297 }
298
299 if (!iswxdigit(pszString[i]) || !iswxdigit(pszString[i + 1]))
300 return FALSE;
301
302 pGuid->Data4[(i - 19) / 2] = CharToByte(pszString[i]) << 4 | CharToByte(pszString[i + 1]);
303 }
304
305 if (pszString[36] == L'\0')
306 return TRUE;
307
308 return FALSE;
309}
static BYTE CharToByte(WCHAR Char)
Definition: misc.c:226
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

Referenced by CreatePrimaryGptPartition(), setid_main(), and UniqueIdDisk().