Reactos
at master 139 lines 3.5 kB view raw
1/* 2 * PROJECT: ReactOS DiskPart 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: base/system/diskpart/remove.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 14EXIT_CODE 15remove_main( 16 _In_ INT argc, 17 _In_ PWSTR *argv) 18{ 19 PWSTR pszSuffix = NULL; 20 WCHAR DriveLetter = UNICODE_NULL; 21 INT i, nExclusive = 0; 22 BOOL bResult; 23 24 DPRINT("remove_main()\n"); 25 26 if (CurrentVolume == NULL) 27 { 28 ConResPuts(StdOut, IDS_SELECT_NO_VOLUME); 29 return EXIT_SUCCESS; 30 } 31 32 if (CurrentVolume->DriveLetter == UNICODE_NULL) 33 { 34 ConResPuts(StdOut, IDS_REMOVE_NO_LETTER); 35 return EXIT_SUCCESS; 36 } 37 38 for (i = 1; i < argc; i++) 39 { 40 if (_wcsicmp(argv[i], L"noerr") == 0) 41 { 42 /* noerr */ 43 ConPuts(StdOut, L"The NOERR option is not supported yet!\n"); 44#if 0 45 bNoErr = TRUE; 46#endif 47 } 48 } 49 50 for (i = 1; i < argc; i++) 51 { 52 if (HasPrefix(argv[i], L"letter=", &pszSuffix)) 53 { 54 if (wcslen(pszSuffix) == 1) 55 { 56 DriveLetter = towupper(*pszSuffix); 57 nExclusive++; 58 } 59 else 60 { 61 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 62 return EXIT_SUCCESS; 63 } 64 } 65 else if (HasPrefix(argv[i], L"mount=", &pszSuffix)) 66 { 67 DPRINT("Mount\n", pszSuffix); 68 ConPuts(StdOut, L"The MOUNT option is not supported yet!\n"); 69 nExclusive++; 70 } 71 else if (_wcsicmp(argv[i], L"all") == 0) 72 { 73 ConPuts(StdOut, L"The ALL option is not supported yet!\n"); 74 nExclusive++; 75 } 76 else if (_wcsicmp(argv[i], L"dismount") == 0) 77 { 78 ConPuts(StdOut, L"The DISMOUNT option is not supported yet!\n"); 79 } 80 else if (_wcsicmp(argv[i], L"noerr") == 0) 81 { 82 /* noerr - Already handled above */ 83 } 84 else 85 { 86 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 87 return EXIT_SUCCESS; 88 } 89 } 90 91 if (CurrentVolume->IsBoot || CurrentVolume->IsSystem) 92 { 93 ConResPuts(StdOut, IDS_ASSIGN_SYSTEM_VOLUME); 94 return EXIT_SUCCESS; 95 } 96 97 if (nExclusive > 1) 98 { 99 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 100 return EXIT_SUCCESS; 101 } 102 103 DPRINT("VolumeName: %S\n", CurrentVolume->VolumeName); 104 DPRINT("DeviceName: %S\n", CurrentVolume->DeviceName); 105 DPRINT("DriveLetter: %C\n", CurrentVolume->DriveLetter); 106 107 if (DriveLetter != UNICODE_NULL) 108 { 109 DPRINT1("DriveLetter: %C\n", DriveLetter); 110 111 if ((DriveLetter < L'C') || (DriveLetter > L'Z')) 112 { 113 ConResPuts(StdOut, IDS_ASSIGN_INVALID_LETTER); 114 return EXIT_SUCCESS; 115 } 116 117 if (DriveLetter != CurrentVolume->DriveLetter) 118 { 119 ConResPuts(StdOut, IDS_REMOVE_WRONG_LETTER); 120 return EXIT_SUCCESS; 121 } 122 } 123 else 124 { 125 DriveLetter = CurrentVolume->DriveLetter; 126 } 127 128 bResult = DeleteDriveLetter(DriveLetter); 129 if (bResult == FALSE) 130 { 131 ConResPuts(StdOut, IDS_REMOVE_FAIL); 132 return EXIT_SUCCESS; 133 } 134 135 CurrentVolume->DriveLetter = UNICODE_NULL; 136 ConResPuts(StdOut, IDS_REMOVE_SUCCESS); 137 138 return EXIT_SUCCESS; 139}