ReactOS 0.4.15-dev-8428-g6910fa6
delete.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS DiskPart
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/diskpart/delete.c
5 * PURPOSE: Manages all the partitions of the OS in an interactive way.
6 * PROGRAMMERS: Lee Schroeder
7 */
8
9#include "diskpart.h"
10
11#define NDEBUG
12#include <debug.h>
13
14static
15BOOL
17 _In_ PPARTENTRY PartEntry)
18{
19 if (IsRecognizedPartition(PartEntry->PartitionType) ||
20 IsContainerPartition(PartEntry->PartitionType))
21 return TRUE;
22
23 return FALSE;
24}
25
26
27BOOL
31{
32 return TRUE;
33}
34
35
36BOOL
40{
41 PPARTENTRY PrevPartEntry;
42 PPARTENTRY NextPartEntry;
43 PPARTENTRY LogicalPartEntry;
45 INT i;
46 BOOL bOverride = FALSE;
48
49 DPRINT("DeletePartition()\n");
50
51 if (CurrentDisk == NULL)
52 {
54 return TRUE;
55 }
56
58 {
60 return TRUE;
61 }
62
64
65 for (i = 2; i < argc; i++)
66 {
67 if (_wcsicmp(argv[i], L"noerr") == 0)
68 {
69 /* noerr */
70 DPRINT("NOERR\n");
71 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
72#if 0
73 bNoErr = TRUE;
74#endif
75 }
76 else if (_wcsicmp(argv[i], L"override") == 0)
77 {
78 /* noerr */
79 DPRINT("OVERRIDE\n");
80 bOverride = TRUE;
81 }
82 else
83 {
85 return TRUE;
86 }
87 }
88
89
90 /* Clear the system partition if it is being deleted */
91#if 0
92 if (List->SystemPartition == PartEntry)
93 {
94 ASSERT(List->SystemPartition);
95 List->SystemPartition = NULL;
96 }
97#endif
98
99 if ((bOverride == FALSE) && (IsKnownPartition(CurrentPartition) == FALSE))
100 {
102 return FALSE;
103 }
104
105 /* Check which type of partition (primary/logical or extended) is being deleted */
107 {
108 /* An extended partition is being deleted: delete all logical partition entries */
110 {
112 LogicalPartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
113
114 /* Dismount the logical partition */
115 DismountVolume(LogicalPartEntry);
116
117 /* Delete it */
118 RtlFreeHeap(RtlGetProcessHeap(), 0, LogicalPartEntry);
119 }
120
122 }
123 else
124 {
125 /* A primary partition is being deleted: dismount it */
127 }
128
129 /* Adjust the unpartitioned disk space entries */
130
131 /* Get pointer to previous and next unpartitioned entries */
134
135 if (PrevPartEntry != NULL && NextPartEntry != NULL)
136 {
137 /* Merge the previous, current and next unpartitioned entries */
138
139 /* Adjust the previous entry length */
140 PrevPartEntry->SectorCount.QuadPart += (CurrentPartition->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart);
141
142 /* Remove the current and next entries */
144 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
145 RemoveEntryList(&NextPartEntry->ListEntry);
146 RtlFreeHeap(RtlGetProcessHeap(), 0, NextPartEntry);
147 }
148 else if (PrevPartEntry != NULL && NextPartEntry == NULL)
149 {
150 /* Merge the current and the previous unpartitioned entries */
151
152 /* Adjust the previous entry length */
154
155 /* Remove the current entry */
157 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
158 }
159 else if (PrevPartEntry == NULL && NextPartEntry != NULL)
160 {
161 /* Merge the current and the next unpartitioned entries */
162
163 /* Adjust the next entry offset and length */
166
167 /* Remove the current entry */
169 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
170 }
171 else
172 {
173 /* Nothing to merge but change the current entry */
177 // CurrentPartition->PartitionIndex = 0;
184 }
185
187
190 if (!NT_SUCCESS(Status))
191 {
193 return TRUE;
194 }
195
197
198 return TRUE;
199}
200
201
202BOOL
204 _In_ INT argc,
205 _In_ PWSTR *argv)
206{
207 return TRUE;
208}
static int argc
Definition: ServiceArgs.c:12
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
static BOOL IsKnownPartition(_In_ PPARTENTRY PartEntry)
Definition: delete.c:16
BOOL DeleteVolume(_In_ INT argc, _In_ PWSTR *argv)
Definition: delete.c:203
BOOL DeletePartition(_In_ INT argc, _In_ PWSTR *argv)
Definition: delete.c:37
BOOL DeleteDisk(_In_ INT argc, _In_ PWSTR *argv)
Definition: delete.c:28
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:88
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:187
#define IDS_DELETE_PARTITION_SUCCESS
Definition: resource.h:33
#define IDS_DELETE_PARTITION_FAIL
Definition: resource.h:32
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
PPARTENTRY GetPrevUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:1901
PDISKENTRY CurrentDisk
Definition: partlist.c:74
PPARTENTRY GetNextUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:1930
#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 RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
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
#define ASSERT(a)
Definition: mode.c:44
#define argv
Definition: mplay32.c:18
#define _In_
Definition: ms_sal.h:308
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:321
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2523
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:2895
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3579
#define DPRINT
Definition: sndvol32.h:73
base of all file and directory entries
Definition: entries.h:83
PPARTENTRY ExtendedPartition
Definition: partlist.h:132
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:129
Definition: typedefs.h:120
BOOLEAN IsPartitioned
Definition: partlist.h:66
UCHAR PartitionType
Definition: partlist.h:53
ULARGE_INTEGER SectorCount
Definition: partlist.h:50
BOOLEAN BootIndicator
Definition: partlist.h:52
WCHAR VolumeLabel[20]
Definition: partlist.h:59
FORMATSTATE FormatState
Definition: partlist.h:61
WCHAR DriveLetter
Definition: partlist.h:58
ULONG OnDiskPartitionNumber
Definition: partlist.h:54
LIST_ENTRY ListEntry
Definition: partlist.h:43
ULONG PartitionNumber
Definition: partlist.h:55
ULARGE_INTEGER StartSector
Definition: partlist.h:49
CHAR FileSystemName[9]
Definition: diskpart.h:115
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static PPARTENTRY CurrentPartition
Definition: usetup.c:74
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550