From 702f9c6f77c3d13360f18738d1149e2c2b57e8ca Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Mon, 12 Jan 2026 19:35:38 +0100 Subject: [PATCH] [DISKPART] Prevent drive letter changes on boot or system volumes --- base/system/diskpart/assign.c | 6 ++++++ base/system/diskpart/lang/de-DE.rc | 1 + base/system/diskpart/lang/en-US.rc | 1 + base/system/diskpart/lang/it-IT.rc | 1 + base/system/diskpart/lang/pl-PL.rc | 1 + base/system/diskpart/lang/pt-PT.rc | 1 + base/system/diskpart/lang/ro-RO.rc | 1 + base/system/diskpart/lang/ru-RU.rc | 1 + base/system/diskpart/lang/sq-AL.rc | 1 + base/system/diskpart/lang/tr-TR.rc | 1 + base/system/diskpart/lang/zh-CN.rc | 1 + base/system/diskpart/lang/zh-TW.rc | 1 + base/system/diskpart/remove.c | 6 ++++++ base/system/diskpart/resource.h | 1 + 14 files changed, 24 insertions(+) diff --git a/base/system/diskpart/assign.c b/base/system/diskpart/assign.c index 9a969347a74..a401f9e4041 100644 --- a/base/system/diskpart/assign.c +++ b/base/system/diskpart/assign.c @@ -74,6 +74,12 @@ assign_main( } } + if (CurrentVolume->IsBoot || CurrentVolume->IsSystem) + { + ConResPuts(StdOut, IDS_ASSIGN_SYSTEM_VOLUME); + return EXIT_SUCCESS; + } + if (nExclusive > 1) { ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); diff --git a/base/system/diskpart/lang/de-DE.rc b/base/system/diskpart/lang/de-DE.rc index cfab204eb02..8b25677852c 100644 --- a/base/system/diskpart/lang/de-DE.rc +++ b/base/system/diskpart/lang/de-DE.rc @@ -32,6 +32,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDer Laufwerkbuchstabe einens System-, Start- oder Auslagerungsvolumes kann nicht neu zugeordnet werden.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/en-US.rc b/base/system/diskpart/lang/en-US.rc index f1b43695364..1d943f7943e 100644 --- a/base/system/diskpart/lang/en-US.rc +++ b/base/system/diskpart/lang/en-US.rc @@ -32,6 +32,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/it-IT.rc b/base/system/diskpart/lang/it-IT.rc index 349b41e40ae..979b58cae9e 100644 --- a/base/system/diskpart/lang/it-IT.rc +++ b/base/system/diskpart/lang/it-IT.rc @@ -39,6 +39,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/pl-PL.rc b/base/system/diskpart/lang/pl-PL.rc index 55f9fa25d17..3faf0d5c0ea 100644 --- a/base/system/diskpart/lang/pl-PL.rc +++ b/base/system/diskpart/lang/pl-PL.rc @@ -32,6 +32,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/pt-PT.rc b/base/system/diskpart/lang/pt-PT.rc index e7c44bf95d5..4aaeb3ed124 100644 --- a/base/system/diskpart/lang/pt-PT.rc +++ b/base/system/diskpart/lang/pt-PT.rc @@ -34,6 +34,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/ro-RO.rc b/base/system/diskpart/lang/ro-RO.rc index 22a99fb88f1..512e6cc64a3 100644 --- a/base/system/diskpart/lang/ro-RO.rc +++ b/base/system/diskpart/lang/ro-RO.rc @@ -40,6 +40,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/ru-RU.rc b/base/system/diskpart/lang/ru-RU.rc index 706d2606385..0e8f8091f8b 100644 --- a/base/system/diskpart/lang/ru-RU.rc +++ b/base/system/diskpart/lang/ru-RU.rc @@ -34,6 +34,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/sq-AL.rc b/base/system/diskpart/lang/sq-AL.rc index 1310385dd46..6f2b2455dcc 100644 --- a/base/system/diskpart/lang/sq-AL.rc +++ b/base/system/diskpart/lang/sq-AL.rc @@ -36,6 +36,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/tr-TR.rc b/base/system/diskpart/lang/tr-TR.rc index 643ba63a8a9..d8622517a4f 100644 --- a/base/system/diskpart/lang/tr-TR.rc +++ b/base/system/diskpart/lang/tr-TR.rc @@ -42,6 +42,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/zh-CN.rc b/base/system/diskpart/lang/zh-CN.rc index 45b7c14e167..d579d105fa3 100644 --- a/base/system/diskpart/lang/zh-CN.rc +++ b/base/system/diskpart/lang/zh-CN.rc @@ -41,6 +41,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/lang/zh-TW.rc b/base/system/diskpart/lang/zh-TW.rc index 26d404dfa2b..f8cbea36f95 100644 --- a/base/system/diskpart/lang/zh-TW.rc +++ b/base/system/diskpart/lang/zh-TW.rc @@ -41,6 +41,7 @@ BEGIN 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" + IDS_ASSIGN_SYSTEM_VOLUME "\nDiskPart cannot reassign the drive letter on a system, boot or pagefile volume.\n" END /* AUTOMOUNT command strings */ diff --git a/base/system/diskpart/remove.c b/base/system/diskpart/remove.c index 3c351da37d0..7e29c034362 100644 --- a/base/system/diskpart/remove.c +++ b/base/system/diskpart/remove.c @@ -88,6 +88,12 @@ remove_main( } } + if (CurrentVolume->IsBoot || CurrentVolume->IsSystem) + { + ConResPuts(StdOut, IDS_ASSIGN_SYSTEM_VOLUME); + return EXIT_SUCCESS; + } + if (nExclusive > 1) { ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); diff --git a/base/system/diskpart/resource.h b/base/system/diskpart/resource.h index edfdc0c6eb8..3e3acadf0d8 100644 --- a/base/system/diskpart/resource.h +++ b/base/system/diskpart/resource.h @@ -32,6 +32,7 @@ #define IDS_ASSIGN_ALREADY_ASSIGNED 1022 #define IDS_ASSIGN_INVALID_LETTER 1023 #define IDS_ASSIGN_NO_MORE_LETTER 1024 +#define IDS_ASSIGN_SYSTEM_VOLUME 1025 #define IDS_CLEAN_FAIL 1030 #define IDS_CLEAN_SUCCESS 1031