[DISKPART] Implement the OVERRIDE option for the DELETE PARTITION command
authorEric Kohl <eric.kohl@reactos.org>
Sun, 5 Jun 2022 08:30:55 +0000 (10:30 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 5 Jun 2022 08:30:55 +0000 (10:30 +0200)
base/system/diskpart/delete.c
base/system/diskpart/diskpart.h

index 6841b3d..feb66e5 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
+static
+BOOL
+IsKnownPartition(
+    _In_ PPARTENTRY PartEntry)
+{
+    if (IsRecognizedPartition(PartEntry->PartitionType) ||
+        IsContainerPartition(PartEntry->PartitionType))
+        return TRUE;
+
+    return FALSE;
+}
+
+
 BOOL
 DeleteDisk(
     _In_ INT argc,
@@ -29,6 +42,8 @@ DeletePartition(
     PPARTENTRY NextPartEntry;
     PPARTENTRY LogicalPartEntry;
     PLIST_ENTRY Entry;
+    INT i;
+    BOOL bOverride = FALSE;
     NTSTATUS Status;
 
     DPRINT("DeletePartition()\n");
@@ -47,6 +62,31 @@ DeletePartition(
 
     ASSERT(CurrentPartition->PartitionType != PARTITION_ENTRY_UNUSED);
 
+    for (i = 2; i < argc; i++)
+    {
+        if (_wcsicmp(argv[i], L"noerr") == 0)
+        {
+            /* noerr */
+            DPRINT("NOERR\n");
+            ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
+#if 0
+            bNoErr = TRUE;
+#endif
+        }
+        else if (_wcsicmp(argv[i], L"override") == 0)
+        {
+            /* noerr */
+            DPRINT("OVERRIDE\n");
+            bOverride = TRUE;
+        }
+        else
+        {
+            ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
+            return TRUE;
+        }
+    }
+
+
     /* Clear the system partition if it is being deleted */
 #if 0
     if (List->SystemPartition == PartEntry)
@@ -56,6 +96,12 @@ DeletePartition(
     }
 #endif
 
+    if ((bOverride == FALSE) && (IsKnownPartition(CurrentPartition) == FALSE))
+    {
+        ConResPuts(StdOut, IDS_DELETE_PARTITION_FAIL);
+        return FALSE;
+    }
+
     /* Check which type of partition (primary/logical or extended) is being deleted */
     if (CurrentDisk->ExtendedPartition == CurrentPartition)
     {
index 755dc7b..fbf63bc 100644 (file)
@@ -19,6 +19,7 @@
 #include <winbase.h>
 #include <winreg.h>
 #include <wincon.h>
+#include <winioctl.h>
 
 #include <errno.h>