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