Skip to content

Commit f6a86c1

Browse files
committed
[DISKPART] Implement the assign command
- Also improve the parameter checks of the remove command. The assign command does not work, because the SetVolumeMountPointW function is not implemented yet.
1 parent c8e1772 commit f6a86c1

File tree

15 files changed

+645
-21
lines changed

15 files changed

+645
-21
lines changed

base/system/diskpart/assign.c

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,151 @@
88

99
#include "diskpart.h"
1010

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

0 commit comments

Comments
 (0)