ReactOS 0.4.16-dev-1993-gbf8741d
delete.c File Reference
#include "diskpart.h"
#include <debug.h>
Include dependency graph for delete.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOL IsKnownPartition (_In_ PPARTENTRY PartEntry)
 
BOOL DeleteDisk (_In_ INT argc, _In_ PWSTR *argv)
 
static VOID DeleteMbrPartition (_In_ BOOL bOverride)
 
static VOID DeleteGptPartition (_In_ BOOL bOverride)
 
BOOL DeletePartition (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL DeleteVolume (_In_ INT argc, _In_ PWSTR *argv)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file delete.c.

Function Documentation

◆ DeleteDisk()

BOOL DeleteDisk ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 28 of file delete.c.

31{
32 return TRUE;
33}
#define TRUE
Definition: types.h:120

◆ DeleteGptPartition()

static VOID DeleteGptPartition ( _In_ BOOL  bOverride)
static

Definition at line 161 of file delete.c.

163{
164 PPARTENTRY PrevPartEntry;
165 PPARTENTRY NextPartEntry;
167
168 /* Clear the system partition if it is being deleted */
169#if 0
170 if (List->SystemPartition == PartEntry)
171 {
172 ASSERT(List->SystemPartition);
173 List->SystemPartition = NULL;
174 }
175#endif
176#if 0
177 if ((bOverride == FALSE) && (IsKnownPartition(CurrentPartition) == FALSE))
178 {
180 return;
181 }
182#endif
183
184#ifdef DUMP_PARTITION_LIST
185 DumpPartitionList(CurrentDisk);
186#endif
187
188 /* Dismount the partition */
190
191 /* Adjust the unpartitioned disk space entries */
192
193 /* Get pointer to previous and next unpartitioned entries */
196
197 if (PrevPartEntry != NULL && NextPartEntry != NULL)
198 {
199 /* Merge the previous, current and next unpartitioned entries */
200
201 /* Adjust the previous entry length */
202 PrevPartEntry->SectorCount.QuadPart += (CurrentPartition->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart);
203
204 /* Remove the current and next entries */
206 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
207 RemoveEntryList(&NextPartEntry->ListEntry);
208 RtlFreeHeap(RtlGetProcessHeap(), 0, NextPartEntry);
209 }
210 else if (PrevPartEntry != NULL && NextPartEntry == NULL)
211 {
212 /* Merge the current and the previous unpartitioned entries */
213
214 /* Adjust the previous entry length */
216
217 /* Remove the current entry */
219 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
220 }
221 else if (PrevPartEntry == NULL && NextPartEntry != NULL)
222 {
223 /* Merge the current and the next unpartitioned entries */
224
225 /* Adjust the next entry offset and length */
228
229 /* Remove the current entry */
231 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
232 }
233 else
234 {
235 /* Nothing to merge but change the current entry */
239 // CurrentPartition->PartitionIndex = 0;
240
244
249 }
250
252
253#ifdef DUMP_PARTITION_LIST
254 DumpPartitionList(CurrentDisk);
255#endif
256
258#ifdef DUMP_PARTITION_TABLE
259 DumpPartitionTable(CurrentDisk);
260#endif
262 if (!NT_SUCCESS(Status))
263 {
265 return;
266 }
267
269}
#define StdOut
Definition: fc.c:14
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
static BOOL IsKnownPartition(_In_ PPARTENTRY PartEntry)
Definition: delete.c:16
#define IDS_DELETE_PARTITION_SUCCESS
Definition: resource.h:42
#define IDS_DELETE_PARTITION_FAIL
Definition: resource.h:41
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
PPARTENTRY GetPrevUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2432
VOID UpdateGptDiskLayout(_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
Definition: partlist.c:2344
PDISKENTRY CurrentDisk
Definition: partlist.c:77
NTSTATUS WriteGptPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1963
PPARTENTRY GetNextUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2461
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
Status
Definition: gdiplustypes.h:25
@ Unformatted
Definition: partlist.h:34
#define ZeroMemory
Definition: minwinbase.h:31
#define ASSERT(a)
Definition: mode.c:44
#define ULL(a, b)
Definition: format_msg.c:27
DWORD64 Attributes
Definition: diskpart.h:114
BOOLEAN IsPartitioned
Definition: partlist.h:82
ULARGE_INTEGER SectorCount
Definition: partlist.h:70
CHAR VolumeLabel[17]
Definition: diskpart.h:137
CHAR DriveLetter
Definition: diskpart.h:136
FORMATSTATE FormatState
Definition: diskpart.h:139
GPT_PARTITION_DATA Gpt
Definition: diskpart.h:129
ULONG OnDiskPartitionNumber
Definition: partlist.h:74
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULONG PartitionNumber
Definition: partlist.h:75
ULARGE_INTEGER StartSector
Definition: partlist.h:69
CHAR FileSystemName[9]
Definition: diskpart.h:138
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static PPARTENTRY CurrentPartition
Definition: usetup.c:78
NTSTATUS DismountVolume(_Inout_ PVOLINFO Volume, _In_ BOOLEAN Force)
Attempts to dismount the designated volume.
Definition: volutil.c:152
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550

Referenced by DeletePartition().

◆ DeleteMbrPartition()

static VOID DeleteMbrPartition ( _In_ BOOL  bOverride)
static

Definition at line 38 of file delete.c.

40{
41 PPARTENTRY PrevPartEntry;
42 PPARTENTRY NextPartEntry;
43 PPARTENTRY LogicalPartEntry;
46
48
49 /* Clear the system partition if it is being deleted */
50#if 0
51 if (List->SystemPartition == PartEntry)
52 {
53 ASSERT(List->SystemPartition);
54 List->SystemPartition = NULL;
55 }
56#endif
57
58 if ((bOverride == FALSE) && (IsKnownPartition(CurrentPartition) == FALSE))
59 {
61 return;
62 }
63
64 /* Check which type of partition (primary/logical or extended) is being deleted */
66 {
67 /* An extended partition is being deleted: delete all logical partition entries */
69 {
71 LogicalPartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
72
73 /* Dismount the logical partition */
74 DismountVolume(LogicalPartEntry);
75
76 /* Delete it */
77 RtlFreeHeap(RtlGetProcessHeap(), 0, LogicalPartEntry);
78 }
79
81 }
82 else
83 {
84 /* A primary partition is being deleted: dismount it */
86 }
87
88 /* Adjust the unpartitioned disk space entries */
89
90 /* Get pointer to previous and next unpartitioned entries */
93
94 if (PrevPartEntry != NULL && NextPartEntry != NULL)
95 {
96 /* Merge the previous, current and next unpartitioned entries */
97
98 /* Adjust the previous entry length */
99 PrevPartEntry->SectorCount.QuadPart += (CurrentPartition->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart);
100
101 /* Remove the current and next entries */
103 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
104 RemoveEntryList(&NextPartEntry->ListEntry);
105 RtlFreeHeap(RtlGetProcessHeap(), 0, NextPartEntry);
106 }
107 else if (PrevPartEntry != NULL && NextPartEntry == NULL)
108 {
109 /* Merge the current and the previous unpartitioned entries */
110
111 /* Adjust the previous entry length */
113
114 /* Remove the current entry */
116 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
117 }
118 else if (PrevPartEntry == NULL && NextPartEntry != NULL)
119 {
120 /* Merge the current and the next unpartitioned entries */
121
122 /* Adjust the next entry offset and length */
125
126 /* Remove the current entry */
128 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
129 }
130 else
131 {
132 /* Nothing to merge but change the current entry */
136 // CurrentPartition->PartitionIndex = 0;
143 }
144
146
149 if (!NT_SUCCESS(Status))
150 {
152 return;
153 }
154
156}
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:71
VOID UpdateMbrDiskLayout(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2167
NTSTATUS WriteMbrPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1839
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
base of all file and directory entries
Definition: entries.h:83
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
Definition: typedefs.h:120
BOOLEAN BootIndicator
Definition: diskpart.h:106
MBR_PARTITION_DATA Mbr
Definition: diskpart.h:128
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by DeletePartition().

◆ DeletePartition()

BOOL DeletePartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 273 of file delete.c.

276{
277 INT i;
278 BOOL bOverride = FALSE;
279
280 DPRINT("DeletePartition()\n");
281
282 if (CurrentDisk == NULL)
283 {
285 return TRUE;
286 }
287
288 if (CurrentPartition == NULL)
289 {
291 return TRUE;
292 }
293
294 for (i = 2; i < argc; i++)
295 {
296 if (_wcsicmp(argv[i], L"noerr") == 0)
297 {
298 /* noerr */
299 DPRINT("NOERR\n");
300 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
301#if 0
302 bNoErr = TRUE;
303#endif
304 }
305 else if (_wcsicmp(argv[i], L"override") == 0)
306 {
307 /* override */
308 DPRINT("OVERRIDE\n");
309 bOverride = TRUE;
310 }
311 else
312 {
314 return TRUE;
315 }
316 }
317
319 {
320 DeleteMbrPartition(bOverride);
321 }
323 {
324 DeleteGptPartition(bOverride);
325 }
326
327 return TRUE;
328}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdErr
Definition: fc.c:15
static VOID DeleteGptPartition(_In_ BOOL bOverride)
Definition: delete.c:161
static VOID DeleteMbrPartition(_In_ BOOL bOverride)
Definition: delete.c:38
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:100
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:203
#define IDS_SELECT_NO_DISK
Definition: resource.h:95
unsigned int BOOL
Definition: ntddk_ex.h:94
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
@ PARTITION_STYLE_GPT
Definition: imports.h:202
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define argv
Definition: mplay32.c: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 DPRINT
Definition: sndvol32.h:73
DWORD PartitionStyle
Definition: diskpart.h:202
int32_t INT
Definition: typedefs.h:58

◆ DeleteVolume()

BOOL DeleteVolume ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 332 of file delete.c.

335{
336 return TRUE;
337}

◆ IsKnownPartition()

static BOOL IsKnownPartition ( _In_ PPARTENTRY  PartEntry)
static

Definition at line 16 of file delete.c.

18{
19 if (IsRecognizedPartition(PartEntry->Mbr.PartitionType) ||
20 IsContainerPartition(PartEntry->Mbr.PartitionType))
21 return TRUE;
22
23 return FALSE;
24}
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:321
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342

Referenced by DeleteGptPartition(), and DeleteMbrPartition().