ReactOS 0.4.16-dev-1990-gfa5cf28
create.c File Reference
#include "diskpart.h"
#include <debug.h>
Include dependency graph for create.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL CreateExtendedPartition (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL CreateLogicalPartition (_In_ INT argc, _In_ PWSTR *argv)
 
static VOID CreatePrimaryMbrPartition (_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
 
static VOID CreatePrimaryGptPartition (_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
 
BOOL CreatePrimaryPartition (_In_ INT argc, _In_ PWSTR *argv)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file create.c.

Function Documentation

◆ CreateExtendedPartition()

BOOL CreateExtendedPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file create.c.

19{
20 PPARTENTRY PartEntry, NewPartEntry;
21 PLIST_ENTRY ListEntry;
22 ULONGLONG ullSize = 0ULL;
23 ULONGLONG ullSectorCount;
24#if 0
25 ULONGLONG ullOffset = 0ULL;
26 BOOL bNoErr = FALSE;
27#endif
28 INT i;
29 PWSTR pszSuffix = NULL;
31
32 if (CurrentDisk == NULL)
33 {
35 return TRUE;
36 }
37
39 {
41 return TRUE;
42 }
43 else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
44 {
45 CREATE_DISK DiskInfo;
47
48 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
49 CreateSignature(&DiskInfo.Mbr.Signature);
50
52 if (!NT_SUCCESS(Status))
53 {
54 DPRINT1("CreateDisk() failed!\n");
55 return TRUE;
56 }
57
60
62 }
63
64 for (i = 3; i < argc; i++)
65 {
66 if (HasPrefix(argv[i], L"size=", &pszSuffix))
67 {
68 /* size=<N> (MB) */
69 DPRINT("Size : %s\n", pszSuffix);
70
71 ullSize = _wcstoui64(pszSuffix, NULL, 10);
72 if ((ullSize == 0) && (errno == ERANGE))
73 {
75 return TRUE;
76 }
77 }
78 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
79 {
80 /* offset=<N> (KB) */
81 DPRINT("Offset : %s\n", pszSuffix);
82 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
83#if 0
84 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
85 if ((ullOffset == 0) && (errno == ERANGE))
86 {
88 return TRUE;
89 }
90#endif
91 }
92 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
93 {
94 /* align=<N> */
95 DPRINT("Align : %s\n", pszSuffix);
96 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
97#if 0
98 bAlign = TRUE;
99#endif
100 }
101 else if (_wcsicmp(argv[i], L"noerr") == 0)
102 {
103 /* noerr */
104 DPRINT("NoErr\n", pszSuffix);
105 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
106#if 0
107 bNoErr = TRUE;
108#endif
109 }
110 else
111 {
113 return TRUE;
114 }
115 }
116
117 DPRINT1("Size: %I64u\n", ullSize);
118#if 0
119 DPRINT1("Offset: %I64u\n", ullOffset);
120#endif
121
123 {
124 ConPuts(StdOut, L"No space left for an extended partition!\n");
125 return TRUE;
126 }
127
129 {
130 ConPuts(StdOut, L"We already have an extended partition on this disk!\n");
131 return TRUE;
132 }
133
134 if (ullSize != 0)
135 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
136 else
137 ullSectorCount = 0;
138
139 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
140
142
143 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
144 if (PartEntry->IsPartitioned)
145 {
146 ConPuts(StdOut, L"No disk space left for an extended partition!\n");
147 return TRUE;
148 }
149
150 if (ullSectorCount == 0)
151 {
152 PartEntry->IsPartitioned = TRUE;
153 PartEntry->New = TRUE;
155 PartEntry->FormatState = Unformatted;
156 PartEntry->FileSystemName[0] = L'\0';
157
158 CurrentPartition = PartEntry;
160 }
161 else
162 {
163 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
164 {
165 PartEntry->IsPartitioned = TRUE;
166 PartEntry->New = TRUE;
168 PartEntry->FormatState = Unformatted;
169 PartEntry->FileSystemName[0] = L'\0';
170
171 CurrentPartition = PartEntry;
173 }
174 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
175 {
176 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
177 if (NewPartEntry == NULL)
178 {
179 ConPuts(StdOut, L"Memory allocation failed!\n");
180 return TRUE;
181 }
182
183 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
184
185 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
186 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
187
188 NewPartEntry->LogicalPartition = FALSE;
189 NewPartEntry->IsPartitioned = TRUE;
190 NewPartEntry->New = TRUE;
191 NewPartEntry->Mbr.PartitionType = PARTITION_EXTENDED;
192 NewPartEntry->FormatState = Unformatted;
193 NewPartEntry->FileSystemName[0] = L'\0';
194
195 PartEntry->StartSector.QuadPart += ullSectorCount;
196 PartEntry->SectorCount.QuadPart -= ullSectorCount;
197
198 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
199
200 CurrentPartition = NewPartEntry;
202 }
203 }
204
207 if (!NT_SUCCESS(Status))
208 {
211 return TRUE;
212 }
213
215
216 return TRUE;
217}
static int argc
Definition: ServiceArgs.c:12
#define ERANGE
Definition: acclib.h:92
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define IDS_CREATE_PARTITION_INVALID_STYLE
Definition: resource.h:39
#define IDS_CREATE_PARTITION_FAIL
Definition: resource.h:37
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:203
#define IDS_SELECT_NO_DISK
Definition: resource.h:95
#define IDS_CREATE_PARTITION_SUCCESS
Definition: resource.h:38
#define PARTITION_EXTENDED
Definition: disk.h:76
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
VOID UpdateMbrDiskLayout(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2167
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
Definition: misc.c:58
PDISKENTRY CurrentDisk
Definition: partlist.c:77
NTSTATUS WriteMbrPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1839
VOID ScanForUnpartitionedMbrDiskSpace(PDISKENTRY DiskEntry)
Definition: partlist.c:662
VOID CreateSignature(_Out_ PDWORD pSignature)
Definition: misc.c:168
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define L(x)
Definition: resources.c:13
#define InsertTailList(ListHead, Entry)
unsigned int BOOL
Definition: ntddk_ex.h:94
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
@ Unformatted
Definition: partlist.h:34
@ PARTITION_STYLE_GPT
Definition: imports.h:202
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define ULL(a, b)
Definition: format_msg.c:27
#define min(a, b)
Definition: monoChain.cc:55
#define argv
Definition: mplay32.c:18
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: _wcsicmp_nt.c:13
#define GetPrimaryPartitionCount(DiskEntry)
Definition: partlist.c:2527
#define DPRINT
Definition: sndvol32.h:73
ULARGE_INTEGER EndSector
Definition: diskpart.h:185
ULONG SectorAlignment
Definition: partlist.h:116
ULARGE_INTEGER SectorCount
Definition: partlist.h:115
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
BOOLEAN Dirty
Definition: partlist.h:136
ULARGE_INTEGER StartSector
Definition: diskpart.h:184
DWORD PartitionStyle
Definition: diskpart.h:202
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:149
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
BOOLEAN IsPartitioned
Definition: partlist.h:82
BOOLEAN New
Definition: partlist.h:85
ULARGE_INTEGER SectorCount
Definition: partlist.h:70
struct _DISKENTRY * DiskEntry
Definition: partlist.h:66
BOOLEAN LogicalPartition
Definition: partlist.h:79
MBR_PARTITION_DATA Mbr
Definition: diskpart.h:128
FORMATSTATE FormatState
Definition: diskpart.h:139
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULARGE_INTEGER StartSector
Definition: partlist.h:69
CHAR FileSystemName[9]
Definition: diskpart.h:138
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
NTSTATUS CreateDisk(_In_ ULONG DiskNumber, _In_ PCREATE_DISK DiskInfo)
Definition: convert.c:15
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint64_t ULONGLONG
Definition: typedefs.h:67
static PPARTENTRY CurrentPartition
Definition: usetup.c:78
unsigned __int64 CDECL _wcstoui64(const wchar_t *nptr, wchar_t **endptr, int base)
Definition: wtoi64.c:200

◆ CreateLogicalPartition()

BOOL CreateLogicalPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 221 of file create.c.

224{
225 PPARTENTRY PartEntry, NewPartEntry;
226 PLIST_ENTRY ListEntry;
227 ULONGLONG ullSize = 0ULL;
228 ULONGLONG ullSectorCount;
229#if 0
230 ULONGLONG ullOffset = 0ULL;
231 BOOL bNoErr = FALSE;
232#endif
234 INT i, length;
235 PWSTR pszSuffix = NULL;
237
238 if (CurrentDisk == NULL)
239 {
241 return TRUE;
242 }
243
245 {
247 return TRUE;
248 }
249
250 for (i = 3; i < argc; i++)
251 {
252 if (HasPrefix(argv[i], L"size=", &pszSuffix))
253 {
254 /* size=<N> (MB) */
255 DPRINT("Size : %s\n", pszSuffix);
256
257 ullSize = _wcstoui64(pszSuffix, NULL, 10);
258 if ((ullSize == 0) && (errno == ERANGE))
259 {
261 return TRUE;
262 }
263 }
264 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
265 {
266 /* offset=<N> (KB) */
267 DPRINT("Offset : %s\n", pszSuffix);
268 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
269#if 0
270 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
271 if ((ullOffset == 0) && (errno == ERANGE))
272 {
274 return TRUE;
275 }
276#endif
277 }
278 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
279 {
280 /* id=<Byte> */
281 DPRINT("Id : %s\n", pszSuffix);
282
283 length = wcslen(pszSuffix);
284 if ((length == 1) || (length == 2))
285 {
286 /* Byte */
287 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
288 if ((PartitionType == 0) && (errno == ERANGE))
289 {
291 return TRUE;
292 }
293 }
294 else
295 {
297 return TRUE;
298 }
299 }
300 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
301 {
302 /* align=<N> */
303 DPRINT("Align : %s\n", pszSuffix);
304 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
305#if 0
306 bAlign = TRUE;
307#endif
308 }
309 else if (_wcsicmp(argv[i], L"noerr") == 0)
310 {
311 /* noerr */
312 DPRINT("NoErr\n", pszSuffix);
313 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
314#if 0
315 bNoErr = TRUE;
316#endif
317 }
318 else
319 {
321 return TRUE;
322 }
323 }
324
325 DPRINT1("Size: %I64u\n", ullSize);
326#if 0
327 DPRINT1("Offset: %I64u\n", ullOffset);
328#endif
329 DPRINT1("Partition Type: %hx\n", PartitionType);
330
331 if (ullSize != 0)
332 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
333 else
334 ullSectorCount = 0;
335
336 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
337
338 for (ListEntry = CurrentDisk->LogicalPartListHead.Flink;
339 ListEntry != &CurrentDisk->LogicalPartListHead;
340 ListEntry = ListEntry->Flink)
341 {
342 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
343 if (PartEntry->IsPartitioned)
344 continue;
345
346 if (ullSectorCount == 0)
347 {
348 PartEntry->IsPartitioned = TRUE;
349 PartEntry->New = TRUE;
350 PartEntry->Mbr.PartitionType = PartitionType;
351 PartEntry->FormatState = Unformatted;
352 PartEntry->FileSystemName[0] = L'\0';
353
354 CurrentPartition = PartEntry;
356 break;
357 }
358 else
359 {
360 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
361 {
362 PartEntry->IsPartitioned = TRUE;
363 PartEntry->New = TRUE;
364 PartEntry->Mbr.PartitionType = PartitionType;
365 PartEntry->FormatState = Unformatted;
366 PartEntry->FileSystemName[0] = L'\0';
367
368 CurrentPartition = PartEntry;
370 break;
371 }
372 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
373 {
374 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
375 if (NewPartEntry == NULL)
376 {
377 ConPuts(StdOut, L"Memory allocation failed!\n");
378 return TRUE;
379 }
380
381 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
382
383 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
384 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
385
386 NewPartEntry->LogicalPartition = TRUE;
387 NewPartEntry->IsPartitioned = TRUE;
388 NewPartEntry->New = TRUE;
389 NewPartEntry->Mbr.PartitionType = PartitionType;
390 NewPartEntry->FormatState = Unformatted;
391 NewPartEntry->FileSystemName[0] = L'\0';
392
393 PartEntry->StartSector.QuadPart += ullSectorCount;
394 PartEntry->SectorCount.QuadPart -= ullSectorCount;
395
396 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
397
398 CurrentPartition = NewPartEntry;
400 break;
401 }
402 }
403 }
404
407 if (!NT_SUCCESS(Status))
408 {
411 return TRUE;
412 }
413
415
416 return TRUE;
417}
#define PARTITION_HUGE
Definition: disk.h:77
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
CHAR PartitionType
Definition: part_xbox.c:32
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ CreatePrimaryGptPartition()

static VOID CreatePrimaryGptPartition ( _In_ ULONGLONG  ullSize,
_In_ PWSTR  pszPartitionType 
)
static

Definition at line 549 of file create.c.

552{
553 PPARTENTRY PartEntry, NewPartEntry;
554 PLIST_ENTRY ListEntry;
555 ULONGLONG ullSectorCount;
556 GUID guidPartitionType;
558
559 /* Partition Type */
560 if (pszPartitionType)
561 {
562 if (!StringToGUID(&guidPartitionType, pszPartitionType))
563 {
565 return;
566 }
567 }
568 else
569 {
570 CopyMemory(&guidPartitionType, &PARTITION_BASIC_DATA_GUID, sizeof(GUID));
571 }
572
573 /* Size */
574 if (ullSize != 0)
575 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
576 else
577 ullSectorCount = 0;
578
579 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
580
581#ifdef DUMP_PARTITION_LIST
582 DumpPartitionList(CurrentDisk);
583#endif
584
585 for (ListEntry = CurrentDisk->PrimaryPartListHead.Flink;
586 ListEntry != &CurrentDisk->PrimaryPartListHead;
587 ListEntry = ListEntry->Flink)
588 {
589 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
590 if (PartEntry->IsPartitioned)
591 continue;
592
593 if (ullSectorCount == 0)
594 {
595 DPRINT("Claim whole unused space!\n");
596 PartEntry->IsPartitioned = TRUE;
597 PartEntry->New = TRUE;
598 CopyMemory(&PartEntry->Gpt.PartitionType, &guidPartitionType, sizeof(GUID));
599 CreateGUID(&PartEntry->Gpt.PartitionId);
600 PartEntry->Gpt.Attributes = 0ULL;
601 PartEntry->PartitionNumber = 0;
602 PartEntry->FormatState = Unformatted;
603 PartEntry->FileSystemName[0] = L'\0';
604
605 CurrentPartition = PartEntry;
607 break;
608 }
609 else
610 {
611 if (ullSectorCount == PartEntry->SectorCount.QuadPart)
612 {
613 DPRINT("Claim matching unused space!\n");
614 PartEntry->IsPartitioned = TRUE;
615 PartEntry->New = TRUE;
616 CopyMemory(&PartEntry->Gpt.PartitionType, &guidPartitionType, sizeof(GUID));
617 CreateGUID(&PartEntry->Gpt.PartitionId);
618 PartEntry->Gpt.Attributes = 0ULL;
619 PartEntry->PartitionNumber = 0;
620 PartEntry->FormatState = Unformatted;
621 PartEntry->FileSystemName[0] = L'\0';
622
623 CurrentPartition = PartEntry;
625 break;
626 }
627 else if (ullSectorCount < PartEntry->SectorCount.QuadPart)
628 {
629 DPRINT("Claim part of unused space\n");
630 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
631 if (NewPartEntry == NULL)
632 {
633 ConPuts(StdOut, L"Memory allocation failed!\n");
634 return;
635 }
636
637 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
638
639 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
640 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
641
642 NewPartEntry->LogicalPartition = FALSE;
643 NewPartEntry->IsPartitioned = TRUE;
644 NewPartEntry->New = TRUE;
645 CopyMemory(&NewPartEntry->Gpt.PartitionType, &guidPartitionType, sizeof(GUID));
646 CreateGUID(&NewPartEntry->Gpt.PartitionId);
647 NewPartEntry->Gpt.Attributes = 0ULL;
648 NewPartEntry->PartitionNumber = 0;
649 NewPartEntry->FormatState = Unformatted;
650 NewPartEntry->FileSystemName[0] = L'\0';
651
652 PartEntry->StartSector.QuadPart += ullSectorCount;
653 PartEntry->SectorCount.QuadPart -= ullSectorCount;
654
655 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
656
657 CurrentPartition = NewPartEntry;
659 break;
660 }
661 }
662 }
663
664#ifdef DUMP_PARTITION_LIST
665 DumpPartitionList(CurrentDisk);
666#endif
667
670 if (!NT_SUCCESS(Status))
671 {
674 return;
675 }
676
678}
VOID CreateGUID(_Out_ GUID *pGuid)
Definition: misc.c:152
VOID UpdateGptDiskLayout(_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
Definition: partlist.c:2344
NTSTATUS WriteGptPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1963
BOOL StringToGUID(_Out_ GUID *pGuid, _In_ PWSTR pszString)
Definition: misc.c:227
#define CopyMemory
Definition: minwinbase.h:29
ULONG SectorCount
Definition: part_xbox.c:31
DWORD64 Attributes
Definition: diskpart.h:114
GPT_PARTITION_DATA Gpt
Definition: diskpart.h:129
ULONG PartitionNumber
Definition: partlist.h:75

Referenced by CreatePrimaryPartition().

◆ CreatePrimaryMbrPartition()

static VOID CreatePrimaryMbrPartition ( _In_ ULONGLONG  ullSize,
_In_ PWSTR  pszPartitionType 
)
static

Definition at line 422 of file create.c.

425{
426 PPARTENTRY PartEntry, NewPartEntry;
427 PLIST_ENTRY ListEntry;
428 ULONGLONG ullSectorCount;
430 INT length;
432
433 if (pszPartitionType)
434 {
435 length = wcslen(pszPartitionType);
436 if ((length != 1) && (length != 2))
437 {
439 return;
440 }
441
442 PartitionType = (UCHAR)wcstoul(pszPartitionType, NULL, 16);
443 if ((PartitionType == 0) && (errno == ERANGE))
444 {
446 return;
447 }
448 }
449 else
450 {
452 }
453
455 {
456 ConPuts(StdOut, L"No space left for another primary partition!\n");
457 return;
458 }
459
460 if (ullSize != 0)
461 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
462 else
463 ullSectorCount = 0;
464
465 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
466
467 for (ListEntry = CurrentDisk->PrimaryPartListHead.Flink;
468 ListEntry != &CurrentDisk->PrimaryPartListHead;
469 ListEntry = ListEntry->Flink)
470 {
471 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
472 if (PartEntry->IsPartitioned)
473 continue;
474
475 if (ullSectorCount == 0)
476 {
477 PartEntry->IsPartitioned = TRUE;
478 PartEntry->New = TRUE;
479 PartEntry->Mbr.PartitionType = PartitionType;
480 PartEntry->FormatState = Unformatted;
481 PartEntry->FileSystemName[0] = L'\0';
482
483 CurrentPartition = PartEntry;
485 break;
486 }
487 else
488 {
489 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
490 {
491 PartEntry->IsPartitioned = TRUE;
492 PartEntry->New = TRUE;
493 PartEntry->Mbr.PartitionType = PartitionType;
494 PartEntry->FormatState = Unformatted;
495 PartEntry->FileSystemName[0] = L'\0';
496
497 CurrentPartition = PartEntry;
499 break;
500 }
501 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
502 {
503 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
504 if (NewPartEntry == NULL)
505 {
506 ConPuts(StdOut, L"Memory allocation failed!\n");
507 return;
508 }
509
510 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
511
512 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
513 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
514
515 NewPartEntry->LogicalPartition = FALSE;
516 NewPartEntry->IsPartitioned = TRUE;
517 NewPartEntry->New = TRUE;
518 NewPartEntry->Mbr.PartitionType = PartitionType;
519 NewPartEntry->FormatState = Unformatted;
520 NewPartEntry->FileSystemName[0] = L'\0';
521
522 PartEntry->StartSector.QuadPart += ullSectorCount;
523 PartEntry->SectorCount.QuadPart -= ullSectorCount;
524
525 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
526
527 CurrentPartition = NewPartEntry;
529 break;
530 }
531 }
532 }
533
536 if (!NT_SUCCESS(Status))
537 {
540 return;
541 }
542
544}

Referenced by CreatePrimaryPartition().

◆ CreatePrimaryPartition()

BOOL CreatePrimaryPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 682 of file create.c.

685{
686 ULONGLONG ullSize = 0ULL;
687#if 0
688 ULONGLONG ullOffset = 0ULL;
689 BOOL bNoErr = FALSE;
690#endif
691 INT i;
692 PWSTR pszSuffix = NULL;
693 PWSTR pszPartitionType = NULL;
694
695 if (CurrentDisk == NULL)
696 {
698 return TRUE;
699 }
700
701 if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
702 {
703 CREATE_DISK DiskInfo;
705
706 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
707 CreateSignature(&DiskInfo.Mbr.Signature);
708
710 if (!NT_SUCCESS(Status))
711 {
712 DPRINT1("CreateDisk() failed!\n");
713 return TRUE;
714 }
715
718
720 }
721
722 for (i = 3; i < argc; i++)
723 {
724 if (HasPrefix(argv[i], L"size=", &pszSuffix))
725 {
726 /* size=<N> (MB) */
727 DPRINT("Size : %s\n", pszSuffix);
728
729 ullSize = _wcstoui64(pszSuffix, NULL, 10);
730 if ((ullSize == 0) && (errno == ERANGE))
731 {
733 return TRUE;
734 }
735 }
736 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
737 {
738 /* offset=<N> (KB) */
739 DPRINT("Offset : %s\n", pszSuffix);
740 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
741#if 0
742 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
743 if ((ullOffset == 0) && (errno == ERANGE))
744 {
746 return TRUE;
747 }
748#endif
749 }
750 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
751 {
752 /* id=<Byte>|<GUID> */
753 DPRINT("Id : %s\n", pszSuffix);
754 pszPartitionType = pszSuffix;
755 }
756 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
757 {
758 /* align=<N> */
759 DPRINT("Align : %s\n", pszSuffix);
760 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
761#if 0
762 bAlign = TRUE;
763#endif
764 }
765 else if (_wcsicmp(argv[i], L"noerr") == 0)
766 {
767 /* noerr */
768 DPRINT("NoErr\n", pszSuffix);
769 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
770#if 0
771 bNoErr = TRUE;
772#endif
773 }
774 else
775 {
777 return TRUE;
778 }
779 }
780
781 DPRINT("Size: %I64u\n", ullSize);
782#if 0
783 DPRINT1("Offset: %I64u\n", ullOffset);
784#endif
785
787 {
788 DPRINT("Partition Type: %s\n", pszPartitionType);
789 CreatePrimaryMbrPartition(ullSize, pszPartitionType);
790 }
792 {
793 CreatePrimaryGptPartition(ullSize, pszPartitionType);
794 }
795
796 return TRUE;
797}
static VOID CreatePrimaryGptPartition(_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
Definition: create.c:549
static VOID CreatePrimaryMbrPartition(_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
Definition: create.c:422