From f6a86c1ab37886b395f5da84393ecb590edbae33 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 28 Dec 2025 20:35:01 +0100 Subject: [PATCH] [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. --- base/system/diskpart/assign.c | 146 +++++++++++- base/system/diskpart/diskpart_msg.mc | 345 ++++++++++++++++++++++++++- base/system/diskpart/lang/de-DE.rc | 12 + base/system/diskpart/lang/en-US.rc | 12 + base/system/diskpart/lang/it-IT.rc | 12 + base/system/diskpart/lang/pl-PL.rc | 12 + base/system/diskpart/lang/pt-PT.rc | 12 + base/system/diskpart/lang/ro-RO.rc | 12 + base/system/diskpart/lang/ru-RU.rc | 12 + base/system/diskpart/lang/sq-AL.rc | 12 + base/system/diskpart/lang/tr-TR.rc | 12 + base/system/diskpart/lang/zh-CN.rc | 12 + base/system/diskpart/lang/zh-TW.rc | 12 + base/system/diskpart/remove.c | 31 ++- base/system/diskpart/resource.h | 12 +- 15 files changed, 645 insertions(+), 21 deletions(-) diff --git a/base/system/diskpart/assign.c b/base/system/diskpart/assign.c index 725c9574aa7..bac6db0bd26 100644 --- a/base/system/diskpart/assign.c +++ b/base/system/diskpart/assign.c @@ -8,7 +8,151 @@ #include "diskpart.h" -BOOL assign_main(INT argc, LPWSTR *argv) +#define NDEBUG +#include + +BOOL +assign_main( + _In_ INT argc, + _In_ LPWSTR *argv) { + WCHAR szMountPoint[4]; + PWSTR pszSuffix = NULL; + WCHAR DriveLetter = UNICODE_NULL; + INT i, nExclusive = 0; + BOOL bResult; + + DPRINT1("assign_main()\n"); + + if (CurrentVolume == NULL) + { + ConResPuts(StdOut, IDS_SELECT_NO_VOLUME); + return TRUE; + } + + for (i = 1; i < argc; i++) + { + if (_wcsicmp(argv[i], L"noerr") == 0) + { + /* noerr */ + DPRINT("NoErr\n", pszSuffix); + ConPuts(StdOut, L"The NOERR option is not supported yet!\n"); +#if 0 + bNoErr = TRUE; +#endif + } + } + + for (i = 1; i < argc; i++) + { + if (HasPrefix(argv[i], L"letter=", &pszSuffix)) + { + if (wcslen(pszSuffix) == 1) + { + DriveLetter = towupper(*pszSuffix); + nExclusive++; + } + else + { + ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); + return TRUE; + } + } + else if (HasPrefix(argv[i], L"mount=", &pszSuffix)) + { + DPRINT("Mount\n", pszSuffix); + ConPuts(StdOut, L"The MOUNT option is not supported yet!\n"); + nExclusive++; + } + else if (_wcsicmp(argv[i], L"noerr") == 0) + { + /* noerr - Already handled above */ + } + else + { + ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); + return TRUE; + } + } + + if (nExclusive > 1) + { + ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); + return TRUE; + } + + DPRINT1("VolumeName: %S\n", CurrentVolume->VolumeName); + DPRINT1("DeviceName: %S\n", CurrentVolume->DeviceName); + DPRINT1("DriveLetter: %C\n", CurrentVolume->DriveLetter); + + if (DriveLetter != UNICODE_NULL) + { + DPRINT1("DriveLetter: %C\n", DriveLetter); + + if ((DriveLetter < L'C') || (DriveLetter > L'Z')) + { + ConResPuts(StdOut, IDS_ASSIGN_INVALID_LETTER); + return TRUE; + } + + if (DriveLetter == CurrentVolume->DriveLetter) + { + ConResPuts(StdOut, IDS_ASSIGN_ALREADY_ASSIGNED); + return TRUE; + } + } + + if (CurrentVolume->DriveLetter != UNICODE_NULL) + { + /* Remove the current drive letter */ + szMountPoint[0] = CurrentVolume->DriveLetter; + szMountPoint[1] = L':'; + szMountPoint[2] = L'\\'; + szMountPoint[3] = UNICODE_NULL; + + bResult = DeleteVolumeMountPointW(szMountPoint); + if (bResult == FALSE) + { + ConResPuts(StdOut, IDS_ASSIGN_FAIL); + return TRUE; + } + + CurrentVolume->DriveLetter = UNICODE_NULL; + } + + if (DriveLetter != UNICODE_NULL) + { + /* Assign the new drive letter */ + szMountPoint[0] = DriveLetter; + szMountPoint[1] = L':'; + szMountPoint[2] = L'\\'; + szMountPoint[3] = UNICODE_NULL; + + bResult = SetVolumeMountPointW(szMountPoint, + CurrentVolume->VolumeName); + if (bResult == FALSE) + { + ConResPuts(StdOut, IDS_ASSIGN_FAIL); + return TRUE; + } + + CurrentVolume->DriveLetter = DriveLetter; + } + else + { + /* TODO: Assign the next drive letter */ +#if 0 + bResult = SetNextDriveLetter(CurrentVolume->VolumeName, + &CurrentVolume->DriveLetter); + if (bResult == FALSE) + { + ConResPuts(StdOut, IDS_ASSIGN_FAIL); + return TRUE; + } +#endif + } + + ConResPuts(StdOut, IDS_REMOVE_SUCCESS); + return TRUE; } diff --git a/base/system/diskpart/diskpart_msg.mc b/base/system/diskpart/diskpart_msg.mc index 35bb7ce7813..6e0774fe8d2 100644 --- a/base/system/diskpart/diskpart_msg.mc +++ b/base/system/diskpart/diskpart_msg.mc @@ -310,34 +310,359 @@ SymbolicName=MSG_COMMAND_ASSIGN Severity=Informational Facility=System Language=English - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=German - + Weist dem Volume mit dem Fokus einen Laufwerkbuchstaben oder + den Pfadnamen des eingebundenen Ordners zu. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= Der Laufwerkbuchstabe, den Sie dem Volume zuweisen + möchten. + + MOUNT= + Der Pfadname des eingebundenen Ordners, den Sie dem Volume + zuweisen möchten. + + NOERR Nur für Skripting. Bei einem Fehler wird die Verarbeitung + von Befehlen fortgesetzt, als sei der Fehler nicht aufge- + treten. Ohne den NOERR-Parameter wird "DiskPart" bei + einem Fehler mit dem entsprechenden Fehlercode beendet. + + Wenn kein Laufwerkbuchstabe oder eingebundener Ordner angegeben ist, + wird der nächste verfügbare Laufwerkbuchstabe zugewiesen. Ein Fehler + wird generiert, wenn der Laufwerkbuchstabe oder Bereitstellungspunkt + bereits verwendet wird. + + Mit dem Befehl "ASSIGN" können Sie den Laufwerkbuchstaben ändern, + der einem Wechseldatenträger zugeordnet ist. + + Startvolumes oder Volumes, die die Auslagerungsdatei + enthalten, können keine Laufwerkbuchstaben zugewiesen werden. Dar\xFCber + hinaus können Laufwerkbuchstaben weder OEM-Partitionen + (sofern kein Start in Windows PE erfolgt) noch GPT-Partitionen (GUID- + Partitionstabelle) zugewiesen werden, die keine Basisdatenpartitionen, + ESP-Partitionen oder Wiederherstellungspartitionen sind. + + Damit dieser Vorgang erfolgreich ausgeführt werden kann, muss ein + Volume ausgewählt werden. + +Beispiel: + + ASSIGN LETTER=D . Language=Polish - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Portugese - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Romanian - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Russian - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Albanian - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Turkish - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Chinese - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . Language=Taiwanese - + Assigns a drive letter or mounted folder pathname to the volume with focus. + +Syntax: ASSIGN [LETTER= | MOUNT=] [NOERR] + + LETTER= The drive letter to assign to the volume. + + MOUNT= + The mounted folder pathname to assign to the volume. + + NOERR For scripting only. When an error is encountered, DiskPart + continues to process commands as if the error did not occur. + Without the NOERR parameter, an error causes DiskPart to exit + with an error code. + + If no drive letter or mounted folder is specified, the next available drive + letter is assigned. If the drive letter or mounted folder is already in use, + an error is generated. + + By using the ASSIGN command, you can change the drive letter associated + with a removable drive. + + You cannot assign drive letters to boot volumes or + volumes that contain the paging file. In addition, you cannot assign + a drive letter to an Original Equipment Manufacturer (OEM) partition + unless booted to Windows PE, or any GUID Partition Table (GPT) partition + other than a basic data partition, an ESP partition or a recovery + partition. + + A volume must be selected for this operation to succeed. + +Example: + + ASSIGN LETTER=D . diff --git a/base/system/diskpart/lang/de-DE.rc b/base/system/diskpart/lang/de-DE.rc index 4b178ec427c..deeaaf8b4cc 100644 --- a/base/system/diskpart/lang/de-DE.rc +++ b/base/system/diskpart/lang/de-DE.rc @@ -15,6 +15,7 @@ Usage: DISKPART [/S filename] [/T timeout] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDie Partition konnte nicht als aktiv markiert werden.\nVergewissern Sie sich, dass diese Partition gültig ist.\n" @@ -23,6 +24,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nEs konnte kein Laufwerksbuchstabe oder Bereitstellungspunkt zugewiesen werden.\nVergewissern Sie sich, dass der Laufwerksbuchstabe oder der Bereitstellungspunkt gültig ist.\n" + IDS_ASSIGN_SUCCESS "\nDer Laufwerksbuchstabe oder der Bereitstellungspunkt wurde zugewiesen.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nDer angegebene Buchstabe wurde diesem Laufwerk bereits zugewiesen.\n" + IDS_ASSIGN_INVALID_LETTER "\nDer angegebene Laufwerksbuchstabe ist kein gültiger Volumebuchstabe.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nEs ist kein freier Laufwerksbuchstabe vorhanden, der diesem Volume zugewiesen werden kann.\nGeben Sie einen Laufwerksbuchstaben frei, und wiederholen Sie den Vorgang.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nDie automatische Bereitstellung von neuen Volumes ist aktiviert.\n" diff --git a/base/system/diskpart/lang/en-US.rc b/base/system/diskpart/lang/en-US.rc index c75a91e69c9..53ea6f3b884 100644 --- a/base/system/diskpart/lang/en-US.rc +++ b/base/system/diskpart/lang/en-US.rc @@ -15,6 +15,7 @@ Usage: DISKPART [/S filename] [/T timeout] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart was unable to mark the partition active.\nMake sure the partition is valid.\n" @@ -23,6 +24,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/it-IT.rc b/base/system/diskpart/lang/it-IT.rc index 1dd49a3abf3..3e9c9de6af3 100644 --- a/base/system/diskpart/lang/it-IT.rc +++ b/base/system/diskpart/lang/it-IT.rc @@ -22,6 +22,7 @@ Usage: DISKPART [/S filename] [/T timeout] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart non ha potuto segnare la partizione come attiva.\nAssicurarsi che la partizione sia valida.\n" @@ -30,6 +31,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/pl-PL.rc b/base/system/diskpart/lang/pl-PL.rc index 20e388fe0e4..628e12dbc8f 100644 --- a/base/system/diskpart/lang/pl-PL.rc +++ b/base/system/diskpart/lang/pl-PL.rc @@ -15,6 +15,7 @@ Sposób użycia: DISKPART [/S nazwa_pliku] [/T limit_czasu] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart nie mógł oznaczyć partycji jako aktywnej.\nUpewnij się, że partycja jest prawidłowa.\n" @@ -23,6 +24,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/pt-PT.rc b/base/system/diskpart/lang/pt-PT.rc index c9294615a7d..a6c1554e770 100644 --- a/base/system/diskpart/lang/pt-PT.rc +++ b/base/system/diskpart/lang/pt-PT.rc @@ -17,6 +17,7 @@ Usage: DISKPART [/S filename] [/T timeout] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart was unable to mark the partition active.\nMake sure the partition is valid.\n" @@ -25,6 +26,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/ro-RO.rc b/base/system/diskpart/lang/ro-RO.rc index b66e7a92dc7..63a8ee5070b 100644 --- a/base/system/diskpart/lang/ro-RO.rc +++ b/base/system/diskpart/lang/ro-RO.rc @@ -23,6 +23,7 @@ Utilizare: DISKPART [/S numefișier] [/T timplimită] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskpart nu a reușit să marcheze partiția activă.\nAsigurați-vă că partiția este validă.\n" @@ -31,6 +32,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/ru-RU.rc b/base/system/diskpart/lang/ru-RU.rc index e68b3969fb3..57eaf51107e 100644 --- a/base/system/diskpart/lang/ru-RU.rc +++ b/base/system/diskpart/lang/ru-RU.rc @@ -17,6 +17,7 @@ BEGIN IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart was unable to mark the partition active.\nMake sure the partition is valid.\n" @@ -25,6 +26,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/sq-AL.rc b/base/system/diskpart/lang/sq-AL.rc index 71a9f57ae5e..98da182a974 100644 --- a/base/system/diskpart/lang/sq-AL.rc +++ b/base/system/diskpart/lang/sq-AL.rc @@ -19,6 +19,7 @@ Usage: DISKPART [/S filename] [/T timeout] [/?]\n\n\ IDS_APP_PROMPT, "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart was unable to mark the partition active.\nMake sure the partition is valid.\n" @@ -27,6 +28,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/tr-TR.rc b/base/system/diskpart/lang/tr-TR.rc index 6a51de17ed9..c21df6f7471 100644 --- a/base/system/diskpart/lang/tr-TR.rc +++ b/base/system/diskpart/lang/tr-TR.rc @@ -25,6 +25,7 @@ Kullanım: DISKPART [/S dosya adı] [/T zaman aşımı] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart, bölümü etkin olarak işaretleyemedi.\nBölümün geçerli olduğundan emin olun.\n" @@ -33,6 +34,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/zh-CN.rc b/base/system/diskpart/lang/zh-CN.rc index ad207ee44e1..837286549f7 100644 --- a/base/system/diskpart/lang/zh-CN.rc +++ b/base/system/diskpart/lang/zh-CN.rc @@ -24,6 +24,7 @@ Usage: DISKPART [/S filename] [/T timeout] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart was unable to mark the partition active.\nMake sure the partition is valid.\n" @@ -32,6 +33,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/lang/zh-TW.rc b/base/system/diskpart/lang/zh-TW.rc index b656e82fc23..68b4b60eb23 100644 --- a/base/system/diskpart/lang/zh-TW.rc +++ b/base/system/diskpart/lang/zh-TW.rc @@ -24,6 +24,7 @@ Usage: DISKPART [/S 檔名] [/T 逾時] [/?]\n\n\ IDS_APP_PROMPT "DISKPART> " END +/* ACTIVE command strings */ STRINGTABLE BEGIN IDS_ACTIVE_FAIL "\nDiskPart 無法把標記磁碟分割為使用中。\n請確認磁碟分割是有效的。\n" @@ -32,6 +33,17 @@ BEGIN IDS_ACTIVE_NO_MBR "\nThe selected disk is not an MBR disk.\nThe ACTIVE command can only be used on an MBR disk.\n" END +/* ASSIGN command strings */ +STRINGTABLE +BEGIN + IDS_ASSIGN_FAIL "\nDiskPart could not assign the drive letter or mount point.\nMake sure the drive letter or mount point is valid.\n" + IDS_ASSIGN_SUCCESS "\nDiskPart successfully assigned the drive letter or mount point.\n" + IDS_ASSIGN_ALREADY_ASSIGNED "\nThe specified letter has already been assigned to this drive.\n" + IDS_ASSIGN_INVALID_LETTER "\nThe letter you specified is not a valid volume letter.\n" + IDS_ASSIGN_NO_MORE_LETTER "\nThere are no free drive letters to assign to this volume.\nPlease free up a drive letter and try again.\n" +END + +/* AUTOMOUNT command strings */ STRINGTABLE BEGIN IDS_AUTOMOUNT_ENABLED "\nAutomatic mounting of new volumes enabled.\n" diff --git a/base/system/diskpart/remove.c b/base/system/diskpart/remove.c index d4726ce4a15..72ef8cb0228 100644 --- a/base/system/diskpart/remove.c +++ b/base/system/diskpart/remove.c @@ -18,8 +18,8 @@ remove_main( { WCHAR szMountPoint[4]; PWSTR pszSuffix = NULL; - PWSTR pszLetter = NULL; - INT i; + WCHAR DriveLetter = UNICODE_NULL; + INT i, nExclusive = 0; BOOL bResult; DPRINT("remove_main()\n"); @@ -52,9 +52,10 @@ remove_main( { if (HasPrefix(argv[i], L"letter=", &pszSuffix)) { - if ((wcslen(pszSuffix) == 1) && (iswalpha(*pszSuffix))) + if (wcslen(pszSuffix) == 1) { - pszLetter = pszSuffix; + DriveLetter = towupper(*pszSuffix); + nExclusive++; } else { @@ -66,10 +67,12 @@ remove_main( { DPRINT("Mount\n", pszSuffix); ConPuts(StdOut, L"The MOUNT option is not supported yet!\n"); + nExclusive++; } else if (_wcsicmp(argv[i], L"all") == 0) { ConPuts(StdOut, L"The ALL option is not supported yet!\n"); + nExclusive++; } else if (_wcsicmp(argv[i], L"dismount") == 0) { @@ -86,19 +89,33 @@ remove_main( } } + if (nExclusive > 1) + { + ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); + return TRUE; + } + DPRINT("VolumeName: %S\n", CurrentVolume->VolumeName); DPRINT("DeviceName: %S\n", CurrentVolume->DeviceName); DPRINT("DriveLetter: %C\n", CurrentVolume->DriveLetter); - if (pszLetter) + if (DriveLetter != UNICODE_NULL) { - if (towupper(pszLetter[0]) != CurrentVolume->DriveLetter) + DPRINT1("DriveLetter: %C\n", DriveLetter); + + if ((DriveLetter < L'C') || (DriveLetter > L'Z')) + { + ConResPuts(StdOut, IDS_ASSIGN_INVALID_LETTER); + return TRUE; + } + + if (DriveLetter != CurrentVolume->DriveLetter) { ConResPuts(StdOut, IDS_REMOVE_WRONG_LETTER); return TRUE; } - szMountPoint[0] = towupper(pszLetter[0]); + szMountPoint[0] = DriveLetter; szMountPoint[1] = L':'; szMountPoint[2] = L'\\'; szMountPoint[3] = UNICODE_NULL; diff --git a/base/system/diskpart/resource.h b/base/system/diskpart/resource.h index 73dfd1477be..fc3fafab93c 100644 --- a/base/system/diskpart/resource.h +++ b/base/system/diskpart/resource.h @@ -27,9 +27,15 @@ #define IDS_AUTOMOUNT_DISABLED 1011 #define IDS_AUTOMOUNT_SCRUBBED 1012 -#define IDS_CLEAN_FAIL 1020 -#define IDS_CLEAN_SUCCESS 1021 -#define IDS_CLEAN_SYSTEM 1022 +#define IDS_ASSIGN_FAIL 1020 +#define IDS_ASSIGN_SUCCESS 1021 +#define IDS_ASSIGN_ALREADY_ASSIGNED 1022 +#define IDS_ASSIGN_INVALID_LETTER 1023 +#define IDS_ASSIGN_NO_MORE_LETTER 1024 + +#define IDS_CLEAN_FAIL 1030 +#define IDS_CLEAN_SUCCESS 1031 +#define IDS_CLEAN_SYSTEM 1032 #define IDS_CONVERT_GPT_ALREADY 1040 #define IDS_CONVERT_GPT_NOT_EMPTY 1041