ReactOS  0.4.15-dev-5461-g062a8f2
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 
14 static
15 BOOL
17  _In_ PPARTENTRY PartEntry)
18 {
19  if (IsRecognizedPartition(PartEntry->PartitionType) ||
20  IsContainerPartition(PartEntry->PartitionType))
21  return TRUE;
22 
23  return FALSE;
24 }
25 
26 
27 BOOL
29  _In_ INT argc,
30  _In_ PWSTR *argv)
31 {
32  return TRUE;
33 }
34 
35 
36 BOOL
38  _In_ INT argc,
39  _In_ PWSTR *argv)
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 
57  if (CurrentPartition == NULL)
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 
202 BOOL
204  _In_ INT argc,
205  _In_ PWSTR *argv)
206 {
207  return TRUE;
208 }
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:88
WCHAR DriveLetter
Definition: partlist.h:58
static int argc
Definition: ServiceArgs.c:12
ULONG PartitionNumber
Definition: partlist.h:55
ULARGE_INTEGER StartSector
Definition: partlist.h:49
WCHAR VolumeLabel[20]
Definition: partlist.h:59
struct _Entry Entry
Definition: kefuncs.h:629
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
ULARGE_INTEGER SectorCount
Definition: partlist.h:50
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
BOOL DeletePartition(_In_ INT argc, _In_ PWSTR *argv)
Definition: delete.c:37
static PPARTENTRY CurrentPartition
Definition: usetup.c:76
PDISKENTRY CurrentDisk
Definition: partlist.c:74
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:316
BOOL DeleteVolume(_In_ INT argc, _In_ PWSTR *argv)
Definition: delete.c:203
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
PPARTENTRY ExtendedPartition
Definition: partlist.h:135
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
LIST_ENTRY ListEntry
Definition: partlist.h:43
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:187
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:2940
#define L(x)
Definition: ntvdm.h:50
static BOOL IsKnownPartition(_In_ PPARTENTRY PartEntry)
Definition: delete.c:16
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
FORMATSTATE FormatState
Definition: partlist.h:61
#define _In_
Definition: ms_sal.h:308
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
#define IDS_DELETE_PARTITION_SUCCESS
Definition: resource.h:33
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2534
Status
Definition: gdiplustypes.h:24
UCHAR PartitionType
Definition: partlist.h:53
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG OnDiskPartitionNumber
Definition: partlist.h:54
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define IDS_DELETE_PARTITION_FAIL
Definition: resource.h:32
Definition: typedefs.h:119
BOOL DeleteDisk(_In_ INT argc, _In_ PWSTR *argv)
Definition: delete.c:28
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
static PPARTENTRY GetPrevUnpartitionedEntry(IN PPARTENTRY PartEntry)
Definition: partlist.c:2717
#define NULL
Definition: types.h:112
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:132
BOOLEAN BootIndicator
Definition: partlist.h:52
#define StdOut
Definition: fc.c:14
static PPARTENTRY GetNextUnpartitionedEntry(IN PPARTENTRY PartEntry)
Definition: partlist.c:2752
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3619
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define DPRINT
Definition: sndvol32.h:71
CHAR FileSystemName[9]
Definition: diskpart.h:113
base of all file and directory entries
Definition: entries.h:82
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOLEAN IsPartitioned
Definition: partlist.h:66
#define StdErr
Definition: fc.c:15