Author: ekohl
Date: Sun Jul 19 17:33:29 2015
New Revision: 68442
URL:
http://svn.reactos.org/svn/reactos?rev=68442&view=rev
Log:
[DISKPART]
Implement the "list disk" and "select disk" commands.
Modified:
trunk/reactos/base/system/diskpart/CMakeLists.txt
trunk/reactos/base/system/diskpart/diskpart.h
trunk/reactos/base/system/diskpart/lang/en-US.rc
trunk/reactos/base/system/diskpart/lang/ro-RO.rc
trunk/reactos/base/system/diskpart/lang/ru-RU.rc
trunk/reactos/base/system/diskpart/lang/sq-AL.rc
trunk/reactos/base/system/diskpart/lang/tr-TR.rc
trunk/reactos/base/system/diskpart/list.c
trunk/reactos/base/system/diskpart/resource.h
trunk/reactos/base/system/diskpart/select.c
Modified: trunk/reactos/base/system/diskpart/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/CMake…
==============================================================================
--- trunk/reactos/base/system/diskpart/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/CMakeLists.txt [iso-8859-1] Sun Jul 19 17:33:29
2015
@@ -42,7 +42,7 @@
add_executable(diskpart ${SOURCE} diskpart.rc)
set_module_type(diskpart win32cui UNICODE)
-add_importlibs(diskpart user32 advapi32 msvcrt kernel32)
+add_importlibs(diskpart user32 advapi32 msvcrt kernel32 ntdll)
if(MSVC)
add_importlibs(diskpart ntdll)
Modified: trunk/reactos/base/system/diskpart/diskpart.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/diskp…
==============================================================================
--- trunk/reactos/base/system/diskpart/diskpart.h [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/diskpart.h [iso-8859-1] Sun Jul 19 17:33:29 2015
@@ -2,8 +2,7 @@
* PROJECT: ReactOS DiskPart
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/diskpart/diskpart.c
- * PURPOSE: Manages all the partitions of the OS in
- * an interactive way
+ * PURPOSE: Manages all the partitions of the OS in an interactive way
* PROGRAMMERS: Lee Schroeder
*/
@@ -13,9 +12,18 @@
/* INCLUDES ******************************************************************/
#include <stdio.h>
+#include <stdlib.h>
#define WIN32_NO_STATUS
#include <windef.h>
+#include <winbase.h>
+#define NTOS_MODE_USER
+#include <ndk/exfuncs.h>
+#include <ndk/iofuncs.h>
+#include <ndk/obfuncs.h>
+#include <ndk/psfuncs.h>
+#include <ndk/rtlfuncs.h>
+#include <ndk/umfuncs.h>
#include "resource.h"
@@ -32,15 +40,20 @@
extern COMMAND cmds[];
/* NOERR codes for the program */
-#define ERROR_NONE 0
-#define ERROR_FATAL 1
-#define ERROR_CMD_ARG 2
-#define ERROR_FILE 3
-#define ERROR_SERVICE 4
-#define ERROR_SYNTAX 5
+//#define ERROR_NONE 0
+//#define ERROR_FATAL 1
+//#define ERROR_CMD_ARG 2
+//#define ERROR_FILE 3
+//#define ERROR_SERVICE 4
+//#define ERROR_SYNTAX 5
#define MAX_STRING_SIZE 1024
#define MAX_ARGS_COUNT 256
+
+/* GLOBAL VARIABLES ***********************************************************/
+
+ULONG CurrentDisk;
+ULONG CurrentPartition;
/* PROTOTYPES *****************************************************************/
Modified: trunk/reactos/base/system/diskpart/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/lang/…
==============================================================================
--- trunk/reactos/base/system/diskpart/lang/en-US.rc [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/lang/en-US.rc [iso-8859-1] Sun Jul 19 17:33:29
2015
@@ -37,9 +37,21 @@
/* Detail header titles */
STRINGTABLE
BEGIN
- IDS_LIST_DISK_HEAD "Disk ### Status\tSize\tFree\tDyn\tGpt\n"
- IDS_LIST_DISK_LINE "-------- ------\t----\t----\t---\t---\n"
- IDS_LIST_VOLUME_HEAD "Volume ###\tLtr\tLabel\n"
+ IDS_LIST_DISK_HEAD "\n Disk ### Status Size Free Dyn
Gpt\n"
+ IDS_LIST_DISK_LINE " -------- ---------- ------- ------- --- ---\n"
+ IDS_LIST_DISK_FORMAT "%c %7lu %-10s %4I64u %-2s %4I64u %-2s %1s
%1s\n"
+ IDS_LIST_VOLUME_HEAD " Volume ### Ltr Label\n"
+END
+
+/* Select command strings */
+STRINGTABLE
+BEGIN
+ IDS_SELECT_NO_DISK "\nThere is no disk currently selected.\nPlease select a disk
and try again.\n\n"
+ IDS_SELECT_DISK "\nDisk %lu is now the selected disk.\n\n"
+ IDS_SELECT_NO_VOLUME "\nThere is no volume currently selected.\nPlease select a
disk and try again.\n\n"
+ IDS_SELECT_VOLUME "\nVolume %lu is now the selected volume.\n\n"
+ IDS_SELECT_NO_PARTITION "\nThere is no partition currently selected.\nPlease
select a disk and try again.\n\n"
+ IDS_SELECT_PARTITION "\nPartition %lu is now the selected partition.\n\n"
END
/* Disk Status */
@@ -58,8 +70,6 @@
/* CMD Messages for commands */
STRINGTABLE
BEGIN
- IDS_MSG_CURRENT_DSK_STATUS "is now the selected disk."
- IDS_MSG_NO_DISK "There is no disk currently selected.\nPlease select a disk and
try again."
IDS_MSG_ARG_SYNTAX_ERROR "The argument(s) specified for this command are not
valid.\nFor more information on the command type:"
END
@@ -111,6 +121,8 @@
BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Error opening script: %s\n"
IDS_ERROR_MSG_BAD_ARG "Error processing argument: %s\n"
+ IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
+ IDS_ERROR_INVALID_DISK "Invalid disk\n"
END
/* Active help descriptions */
Modified: trunk/reactos/base/system/diskpart/lang/ro-RO.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/lang/…
==============================================================================
--- trunk/reactos/base/system/diskpart/lang/ro-RO.rc [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/lang/ro-RO.rc [iso-8859-1] Sun Jul 19 17:33:29
2015
@@ -38,9 +38,21 @@
/* Detail header titles */
STRINGTABLE
BEGIN
- IDS_LIST_DISK_HEAD "Disc ### Stare\tDimensiune\tLiber\tDyn\tGpt\n"
- IDS_LIST_DISK_LINE "-------- ------\t----\t----\t---\t---\n"
+ IDS_LIST_DISK_HEAD "\n Disc ### Stare Dimensiune Liber Dyn
Gpt\n"
+ IDS_LIST_DISK_LINE " -------- ---------- ---------- ------- ---
---\n"
+ IDS_LIST_DISK_FORMAT "%c %7lu %-10s %4I64u %-2s %4I64u %-2s %1s
%1s\n"
IDS_LIST_VOLUME_HEAD "Volum ###\tLtr\tEtichetÄ\n"
+END
+
+/* Select command strings */
+STRINGTABLE
+BEGIN
+ IDS_SELECT_NO_DISK "\nThere is no disk currently selected.\nPlease select a disk
and try again.\n\n"
+ IDS_SELECT_DISK "\nDisk %lu is now the selected disk.\n\n"
+ IDS_SELECT_NO_VOLUME "\nThere is no volume currently selected.\nPlease select a
disk and try again.\n\n"
+ IDS_SELECT_VOLUME "\nVolume %lu is now the selected volume.\n\n"
+ IDS_SELECT_NO_PARTITION "\nThere is no partition currently selected.\nPlease
select a disk and try again.\n\n"
+ IDS_SELECT_PARTITION "\nPartition %lu is now the selected partition.\n\n"
END
/* Disk Status */
@@ -59,8 +71,6 @@
/* CMD Messages for commands */
STRINGTABLE
BEGIN
- IDS_MSG_CURRENT_DSK_STATUS " a devenit discul curent."
- IDS_MSG_NO_DISK "Momentan nici un disc nu este selectat.\nAlegeÈi un disc apoi
reîncercaÈi."
IDS_MSG_ARG_SYNTAX_ERROR "Argument(e) nevalid(e) pentru aceastÄ
comandÄ.\nPentru mai multe informaÈii, executaÈi comanda:"
END
@@ -112,6 +122,8 @@
BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Eroare la deschiderea fiÈierului script: %s\n"
IDS_ERROR_MSG_BAD_ARG "Eroare la prelucrarea argumentului: %s\n"
+ IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
+ IDS_ERROR_INVALID_DISK "Invalid disk\n"
END
/* Active help descriptions */
Modified: trunk/reactos/base/system/diskpart/lang/ru-RU.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/lang/…
==============================================================================
--- trunk/reactos/base/system/diskpart/lang/ru-RU.rc [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/lang/ru-RU.rc [iso-8859-1] Sun Jul 19 17:33:29
2015
@@ -39,9 +39,21 @@
/* Detail header titles */
STRINGTABLE
BEGIN
- IDS_LIST_DISK_HEAD "ÐиÑк ###
СоÑÑоÑние\tРазмеÑ\tСвободно\tÐин\tGPT\n"
- IDS_LIST_DISK_LINE "-------- ---------\t------\t--------\t---\t---\n"
+ IDS_LIST_DISK_HEAD "\n ÐиÑк ### СоÑÑоÑние РазмеÑ
Свободно Ðин GPT\n"
+ IDS_LIST_DISK_LINE " -------- ---------- ------- -------- --- ---\n"
+ IDS_LIST_DISK_FORMAT "%c %7lu %-10s %4I64u %-2s %4I64u %-2s %1s
%1s\n"
IDS_LIST_VOLUME_HEAD "Том ###\tÐмÑ\tÐеÑка\n"
+END
+
+/* Select command strings */
+STRINGTABLE
+BEGIN
+ IDS_SELECT_NO_DISK "\nThere is no disk currently selected.\nPlease select a disk
and try again.\n\n"
+ IDS_SELECT_DISK "\nDisk %lu is now the selected disk.\n\n"
+ IDS_SELECT_NO_VOLUME "\nThere is no volume currently selected.\nPlease select a
disk and try again.\n\n"
+ IDS_SELECT_VOLUME "\nVolume %lu is now the selected volume.\n\n"
+ IDS_SELECT_NO_PARTITION "\nThere is no partition currently selected.\nPlease
select a disk and try again.\n\n"
+ IDS_SELECT_PARTITION "\nPartition %lu is now the selected partition.\n\n"
END
/* Disk Status */
@@ -60,8 +72,6 @@
/* CMD Messages for commands */
STRINGTABLE
BEGIN
- IDS_MSG_CURRENT_DSK_STATUS "вÑбÑан ÑекÑÑим диÑком."
- IDS_MSG_NO_DISK "ÐиÑк Ð´Ð»Ñ Ð¿ÑеобÑÐ°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð½Ðµ
вÑбÑан.\nÐÑбеÑиÑе диÑк и повÑоÑиÑе попÑÑкÑ."
IDS_MSG_ARG_SYNTAX_ERROR "Ð£ÐºÐ°Ð·Ð°Ð½Ñ Ð½ÐµÐ²ÐµÑнÑе паÑамеÑÑÑ
командÑ.\nЧÑÐ¾Ð±Ñ Ð¿Ð¾Ð»ÑÑиÑÑ Ð´Ð¾Ð¿Ð¾Ð»Ð½Ð¸ÑелÑнÑе ÑведениÑ
о данной команде, введиÑе:"
END
@@ -113,6 +123,8 @@
BEGIN
IDS_ERROR_MSG_NO_SCRIPT "ÐÑибка оÑкÑÑÑÐ¸Ñ ÑкÑипÑа:
%s\n"
IDS_ERROR_MSG_BAD_ARG "ÐÑибка обÑабоÑки паÑамеÑÑов:
%s\n"
+ IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
+ IDS_ERROR_INVALID_DISK "Invalid disk\n"
END
/* Active help descriptions */
Modified: trunk/reactos/base/system/diskpart/lang/sq-AL.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/lang/…
==============================================================================
--- trunk/reactos/base/system/diskpart/lang/sq-AL.rc [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/lang/sq-AL.rc [iso-8859-1] Sun Jul 19 17:33:29
2015
@@ -41,9 +41,21 @@
/* Detail header titles */
STRINGTABLE
BEGIN
- IDS_LIST_DISK_HEAD "Disk ### Status\tSize\tFree\tDyn\tGpt\n"
- IDS_LIST_DISK_LINE "-------- ------\t----\t----\t---\t---\n"
+ IDS_LIST_DISK_HEAD "\n Disk ### Status Size Free Dyn
Gpt\n"
+ IDS_LIST_DISK_LINE " -------- ---------- ------- ------- --- ---\n"
+ IDS_LIST_DISK_FORMAT "%c %7lu %-10s %4I64u %-2s %4I64u %-2s %1s
%1s\n"
IDS_LIST_VOLUME_HEAD "Volume ###\tLtr\tLabel\n"
+END
+
+/* Select command strings */
+STRINGTABLE
+BEGIN
+ IDS_SELECT_NO_DISK "\nThere is no disk currently selected.\nPlease select a disk
and try again.\n\n"
+ IDS_SELECT_DISK "\nDisk %lu is now the selected disk.\n\n"
+ IDS_SELECT_NO_VOLUME "\nThere is no volume currently selected.\nPlease select a
disk and try again.\n\n"
+ IDS_SELECT_VOLUME "\nVolume %lu is now the selected volume.\n\n"
+ IDS_SELECT_NO_PARTITION "\nThere is no partition currently selected.\nPlease
select a disk and try again.\n\n"
+ IDS_SELECT_PARTITION "\nPartition %lu is now the selected partition.\n\n"
END
/* Disk Status */
@@ -62,8 +74,6 @@
/* CMD Messages for commands */
STRINGTABLE
BEGIN
- IDS_MSG_CURRENT_DSK_STATUS "është disku i përzgjedhur."
- IDS_MSG_NO_DISK "Nuk ka disk të përzgjedhur.\nJu lutem zgjidhni një disk dhe
provoni përsëri."
IDS_MSG_ARG_SYNTAX_ERROR "Argumente(t) e specifikuara per kete komande nuk jane
të vlefshme.\nPër më shume informacione mbi komanden shkruani:"
END
@@ -115,6 +125,8 @@
BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Error në hapjen e skriptes: %s\n"
IDS_ERROR_MSG_BAD_ARG "Error argumenti i procesimit: %s\n"
+ IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
+ IDS_ERROR_INVALID_DISK "Invalid disk\n"
END
/* Active help descriptions */
Modified: trunk/reactos/base/system/diskpart/lang/tr-TR.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/lang/…
==============================================================================
--- trunk/reactos/base/system/diskpart/lang/tr-TR.rc [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/lang/tr-TR.rc [iso-8859-1] Sun Jul 19 17:33:29
2015
@@ -39,9 +39,21 @@
/* Detail header titles */
STRINGTABLE
BEGIN
- IDS_LIST_DISK_HEAD "Disk ### Durum\tBoyut\tBoÅ\tDev\tGpt\n"
- IDS_LIST_DISK_LINE "-------- ------\t----\t----\t---\t---\n"
+ IDS_LIST_DISK_HEAD "\n Disk ### Durum Boyut BoÅ Dev
Gpt\n"
+ IDS_LIST_DISK_LINE " -------- ---------- ------- ------- --- ---\n"
+ IDS_LIST_DISK_FORMAT "%c %7lu %-10s %4I64u %-2s %4I64u %-2s %1s
%1s\n"
IDS_LIST_VOLUME_HEAD "Birim ###\tHarf\tEtiket\n"
+END
+
+/* Select command strings */
+STRINGTABLE
+BEGIN
+ IDS_SELECT_NO_DISK "\nThere is no disk currently selected.\nPlease select a disk
and try again.\n\n"
+ IDS_SELECT_DISK "\nDisk %lu is now the selected disk.\n\n"
+ IDS_SELECT_NO_VOLUME "\nThere is no volume currently selected.\nPlease select a
disk and try again.\n\n"
+ IDS_SELECT_VOLUME "\nVolume %lu is now the selected volume.\n\n"
+ IDS_SELECT_NO_PARTITION "\nThere is no partition currently selected.\nPlease
select a disk and try again.\n\n"
+ IDS_SELECT_PARTITION "\nPartition %lu is now the selected partition.\n\n"
END
/* Disk Status */
@@ -60,8 +72,6 @@
/* CMD Messages for commands */
STRINGTABLE
BEGIN
- IDS_MSG_CURRENT_DSK_STATUS "Åimdi seçili disktir."
- IDS_MSG_NO_DISK "Bir disk Åimdilik seçilmemiÅ.\nLütfen bir disk seçiniz ve
yeniden deneyiniz."
IDS_MSG_ARG_SYNTAX_ERROR "Bu komut için belirtilen deÄiÅtirgen(ler) geçerli
deÄil.\nKomu türü üzerinde daha çok bilgi için:"
END
@@ -113,6 +123,8 @@
BEGIN
IDS_ERROR_MSG_NO_SCRIPT "Betik açmada yanlıÅlık: %s\n"
IDS_ERROR_MSG_BAD_ARG "DeÄiÅtirgen iÅlemede yanlıÅlık: %s\n"
+ IDS_ERROR_INVALID_ARGS "Invalid arguments\n"
+ IDS_ERROR_INVALID_DISK "Invalid disk\n"
END
/* Active help descriptions */
Modified: trunk/reactos/base/system/diskpart/list.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/list.…
==============================================================================
--- trunk/reactos/base/system/diskpart/list.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/list.c [iso-8859-1] Sun Jul 19 17:33:29 2015
@@ -2,38 +2,168 @@
* PROJECT: ReactOS DiskPart
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/diskpart/list.c
- * PURPOSE: Manages all the partitions of the OS in
- * an interactive way
+ * PURPOSE: Manages all the partitions of the OS in an interactive way
* PROGRAMMERS: Lee Schroeder
*/
#include "diskpart.h"
-static VOID list_disk(VOID)
+#define NDEBUG
+#include <debug.h>
+
+static
+ULONGLONG
+RoundingDivide(
+ IN ULONGLONG Dividend,
+ IN ULONGLONG Divisor)
{
+ return (Dividend + Divisor / 2) / Divisor;
+}
+
+
+static
+VOID
+ListDisk(VOID)
+{
+ WCHAR Buffer[MAX_PATH];
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ SYSTEM_DEVICE_INFORMATION Sdi;
+ IO_STATUS_BLOCK Iosb;
+ DISK_GEOMETRY DiskGeometry;
+ ULONG ReturnSize;
+ ULONG DiskNumber;
+ UNICODE_STRING Name;
+ HANDLE FileHandle;
+ NTSTATUS Status;
+
+ ULARGE_INTEGER DiskSize;
+ ULARGE_INTEGER FreeSize;
+ LPWSTR lpSizeUnit;
+ LPWSTR lpFreeUnit;
+
+
+ Status = NtQuerySystemInformation(SystemDeviceInformation,
+ &Sdi,
+ sizeof(SYSTEM_DEVICE_INFORMATION),
+ &ReturnSize);
+ if (!NT_SUCCESS(Status))
+ {
+ return;
+ }
+
/* Header labels */
PrintResourceString(IDS_LIST_DISK_HEAD);
PrintResourceString(IDS_LIST_DISK_LINE);
- printf("\n\n");
+ for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++)
+ {
+ swprintf(Buffer,
+ L"\\Device\\Harddisk%d\\Partition0",
+ DiskNumber);
+ RtlInitUnicodeString(&Name,
+ Buffer);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &Name,
+ 0,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ FILE_READ_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+ &ObjectAttributes,
+ &Iosb,
+ FILE_SHARE_READ,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ if (NT_SUCCESS(Status))
+ {
+ Status = NtDeviceIoControlFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &Iosb,
+ IOCTL_DISK_GET_DRIVE_GEOMETRY,
+ NULL,
+ 0,
+ &DiskGeometry,
+ sizeof(DISK_GEOMETRY));
+ if (NT_SUCCESS(Status))
+ {
+ DiskSize.QuadPart = DiskGeometry.Cylinders.QuadPart *
+ (ULONGLONG)DiskGeometry.TracksPerCylinder *
+ (ULONGLONG)DiskGeometry.SectorsPerTrack *
+ (ULONGLONG)DiskGeometry.BytesPerSector;
+ if (DiskSize.QuadPart >= 10737418240) /* 10 GB */
+ {
+ DiskSize.QuadPart = RoundingDivide(DiskSize.QuadPart, 1073741824);
+ lpSizeUnit = L"GB";
+ }
+ else
+ {
+ DiskSize.QuadPart = RoundingDivide(DiskSize.QuadPart, 1048576);
+ if (DiskSize.QuadPart == 0)
+ DiskSize.QuadPart = 1;
+ lpSizeUnit = L"MB";
+ }
+
+ /* FIXME */
+ FreeSize.QuadPart = 0;
+ lpFreeUnit = L"B";
+
+ PrintResourceString(IDS_LIST_DISK_FORMAT,
+ (CurrentDisk == DiskNumber) ? L'*': '
',
+ DiskNumber,
+ L"Online",
+ DiskSize.QuadPart,
+ lpSizeUnit,
+ FreeSize.QuadPart,
+ lpFreeUnit,
+ L" ",
+ L" ");
+ }
+ else
+ {
+ printf("Status 0x%lx\n", Status);
+
+ }
+
+ NtClose(FileHandle);
+ }
+ else
+ {
+ printf("Status 0x%lx\n", Status);
+
+ }
+ }
+
+ wprintf(L"\n\n");
}
-static VOID list_partition(VOID)
+static
+VOID
+ListPartition(VOID)
{
printf("List Partition!!\n");
}
-static VOID list_volume(VOID)
+static
+VOID
+ListVolume(VOID)
{
PrintResourceString(IDS_LIST_VOLUME_HEAD);
}
-static VOID list_vdisk(VOID)
+static
+VOID
+ListVdisk(VOID)
{
printf("List VDisk!!\n");
}
-BOOL list_main(INT argc, LPWSTR *argv)
+BOOL
+list_main(
+ INT argc,
+ LPWSTR *argv)
{
/* gets the first word from the string */
if (argc == 1)
@@ -43,14 +173,14 @@
}
/* determines which to list (disk, partition, etc.) */
- if(!wcsicmp(argv[1], L"disk"))
- list_disk();
- else if(!wcsicmp(argv[1], L"partition"))
- list_partition();
- else if(!wcsicmp(argv[1], L"volume"))
- list_volume();
- else if(!wcsicmp(argv[1], L"vdisk"))
- list_vdisk();
+ if (!wcsicmp(argv[1], L"disk"))
+ ListDisk();
+ else if (!wcsicmp(argv[1], L"partition"))
+ ListPartition();
+ else if (!wcsicmp(argv[1], L"volume"))
+ ListVolume();
+ else if (!wcsicmp(argv[1], L"vdisk"))
+ ListVdisk();
else
PrintResourceString(IDS_HELP_CMD_LIST);
Modified: trunk/reactos/base/system/diskpart/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/resou…
==============================================================================
--- trunk/reactos/base/system/diskpart/resource.h [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/resource.h [iso-8859-1] Sun Jul 19 17:33:29 2015
@@ -2,8 +2,7 @@
* PROJECT: ReactOS DiskPart
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/diskpart/lang/resource.h
- * PURPOSE: Manages all the partitions of the OS in
- * an interactive way
+ * PURPOSE: Manages all the partitions of the OS in an interactive way
* PROGRAMMERS: Lee Schroeder
*/
@@ -33,9 +32,17 @@
#define IDS_DETAIL_INFO_CRASH_DSK 19
#define IDS_DETAIL_INFO_CLST_DSK 20
-#define IDS_LIST_DISK_HEAD 21
-#define IDS_LIST_DISK_LINE 22
-#define IDS_LIST_VOLUME_HEAD 23
+#define IDS_LIST_DISK_HEAD 3300
+#define IDS_LIST_DISK_LINE 3301
+#define IDS_LIST_DISK_FORMAT 3302
+#define IDS_LIST_VOLUME_HEAD 3303
+
+#define IDS_SELECT_NO_DISK 4400
+#define IDS_SELECT_DISK 4401
+#define IDS_SELECT_NO_VOLUME 4402
+#define IDS_SELECT_VOLUME 4403
+#define IDS_SELECT_NO_PARTITION 4404
+#define IDS_SELECT_PARTITION 4405
#define IDS_STATUS_YES 31
#define IDS_STATUS_NO 32
@@ -46,8 +53,6 @@
#define IDS_STATUS_OFFLINE 37
#define IDS_STATUS_NO_MEDIA 38
-#define IDS_MSG_CURRENT_DSK_STATUS 39
-#define IDS_MSG_NO_DISK 40
#define IDS_MSG_ARG_SYNTAX_ERROR 41
#define IDS_HELP_CMD_DESC_ACTIVE 58
@@ -128,3 +133,7 @@
#define IDS_HELP_CMD_SETID 138
#define IDS_HELP_CMD_SHRINK 139
#define IDS_HELP_CMD_UNIQUEID 140
+
+
+#define IDS_ERROR_INVALID_ARGS 211
+#define IDS_ERROR_INVALID_DISK 212
Modified: trunk/reactos/base/system/diskpart/select.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/diskpart/selec…
==============================================================================
--- trunk/reactos/base/system/diskpart/select.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/diskpart/select.c [iso-8859-1] Sun Jul 19 17:33:29 2015
@@ -2,14 +2,140 @@
* PROJECT: ReactOS DiskPart
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/diskpart/select.c
- * PURPOSE: Manages all the partitions of the OS in
- * an interactive way
+ * PURPOSE: Manages all the partitions of the OS in an interactive way
* PROGRAMMERS: Lee Schroeder
*/
#include "diskpart.h"
-BOOL select_main(INT argc, LPWSTR *argv)
+#define NDEBUG
+#include <debug.h>
+
+
+ULONG CurrentDisk = (ULONG)-1;
+ULONG CurrentPartition = (ULONG)-1;
+
+
+static
+VOID
+SelectDisk(
+ INT argc,
+ LPWSTR *argv)
{
+ SYSTEM_DEVICE_INFORMATION Sdi;
+ ULONG ReturnSize;
+ NTSTATUS Status;
+ LONG value;
+ LPWSTR endptr = NULL;
+
+ DPRINT("Select Disk()\n");
+
+ if (argc > 3)
+ {
+ PrintResourceString(IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ if (argc == 2)
+ {
+ if (CurrentDisk == (ULONG)-1)
+ PrintResourceString(IDS_SELECT_NO_DISK);
+ else
+ PrintResourceString(IDS_SELECT_DISK, CurrentDisk);
+ return;
+ }
+
+ value = wcstol(argv[2], &endptr, 10);
+ if (((value == 0) && (endptr == argv[2])) ||
+ (value < 0))
+ {
+ PrintResourceString(IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ Status = NtQuerySystemInformation(SystemDeviceInformation,
+ &Sdi,
+ sizeof(SYSTEM_DEVICE_INFORMATION),
+ &ReturnSize);
+ if (!NT_SUCCESS(Status))
+ {
+ return;
+ }
+
+ if ((ULONG)value >= Sdi.NumberOfDisks)
+ {
+ PrintResourceString(IDS_ERROR_INVALID_DISK);
+ return;
+ }
+
+ CurrentDisk = (ULONG)value;
+ CurrentPartition = (ULONG)-1;
+
+ PrintResourceString(IDS_SELECT_DISK, CurrentDisk);
+}
+
+
+static
+VOID
+SelectPartition(
+ INT argc,
+ LPWSTR *argv)
+{
+ LONG value;
+ LPWSTR endptr = NULL;
+
+ DPRINT("Select Partition()\n");
+
+ if (argc > 3)
+ {
+ PrintResourceString(IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ if (argc == 2)
+ {
+ if (CurrentPartition == (ULONG)-1)
+ PrintResourceString(IDS_SELECT_NO_PARTITION);
+ else
+ PrintResourceString(IDS_SELECT_PARTITION, CurrentPartition);
+ return;
+ }
+
+ value = wcstol(argv[2], &endptr, 10);
+ if (((value == 0) && (endptr == argv[2])) ||
+ (value < 0))
+ {
+ PrintResourceString(IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ /* FIXME: Check the new partition number */
+
+ CurrentPartition = (ULONG)value;
+
+ PrintResourceString(IDS_SELECT_PARTITION, CurrentPartition);
+}
+
+
+BOOL
+select_main(
+ INT argc,
+ LPWSTR *argv)
+{
+ /* gets the first word from the string */
+ if (argc == 1)
+ {
+ PrintResourceString(IDS_HELP_CMD_SELECT);
+ return TRUE;
+ }
+
+ /* determines which to list (disk, partition, etc.) */
+ if (!wcsicmp(argv[1], L"disk"))
+ SelectDisk(argc, argv);
+ else if (!wcsicmp(argv[1], L"partition"))
+ SelectPartition(argc, argv);
+ else
+ PrintResourceString(IDS_HELP_CMD_SELECT);
+
return TRUE;
}