2011-09-24 10:33:33 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS DiskPart
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: base/system/diskpart/select.c
|
2016-10-01 22:58:21 +00:00
|
|
|
* PURPOSE: Manages all the partitions of the OS in an interactive way.
|
2011-09-24 10:33:33 +00:00
|
|
|
* PROGRAMMERS: Lee Schroeder
|
|
|
|
*/
|
2014-01-13 13:07:50 +00:00
|
|
|
|
2011-09-24 10:33:33 +00:00
|
|
|
#include "diskpart.h"
|
|
|
|
|
2015-07-19 17:33:29 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2015-07-19 17:33:29 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
SelectDisk(
|
|
|
|
INT argc,
|
|
|
|
LPWSTR *argv)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PDISKENTRY DiskEntry;
|
|
|
|
LONG lValue;
|
2015-07-19 17:33:29 +00:00
|
|
|
LPWSTR endptr = NULL;
|
|
|
|
|
|
|
|
DPRINT("Select Disk()\n");
|
|
|
|
|
|
|
|
if (argc > 3)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2015-07-19 17:33:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
if (CurrentDisk == NULL)
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_SELECT_NO_DISK);
|
2015-07-19 17:33:29 +00:00
|
|
|
else
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_DISK, CurrentDisk->DiskNumber);
|
2015-07-19 17:33:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
lValue = wcstol(argv[2], &endptr, 10);
|
|
|
|
if (((lValue == 0) && (endptr == argv[2])) ||
|
|
|
|
(lValue < 0))
|
2015-07-19 17:33:29 +00:00
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2015-07-19 17:33:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
CurrentDisk = NULL;
|
2015-07-19 17:33:29 +00:00
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
Entry = DiskListHead.Flink;
|
|
|
|
while (Entry != &DiskListHead)
|
2015-07-19 17:33:29 +00:00
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
|
2015-07-19 17:33:29 +00:00
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
if (DiskEntry->DiskNumber == (ULONG)lValue)
|
|
|
|
{
|
|
|
|
CurrentDisk = DiskEntry;
|
|
|
|
CurrentPartition = NULL;
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_DISK, CurrentDisk->DiskNumber);
|
2015-07-20 19:17:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-19 17:33:29 +00:00
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_SELECT_DISK_INVALID);
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
SelectPartition(
|
|
|
|
INT argc,
|
|
|
|
LPWSTR *argv)
|
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PPARTENTRY PartEntry;
|
|
|
|
LONG lValue;
|
2015-07-19 17:33:29 +00:00
|
|
|
LPWSTR endptr = NULL;
|
2015-07-20 19:17:06 +00:00
|
|
|
ULONG PartNumber = 1;
|
2015-07-19 17:33:29 +00:00
|
|
|
|
|
|
|
DPRINT("Select Partition()\n");
|
|
|
|
|
|
|
|
if (argc > 3)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2015-07-19 17:33:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
if (CurrentDisk == NULL)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_SELECT_PARTITION_NO_DISK);
|
2015-07-20 19:17:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-19 17:33:29 +00:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
if (CurrentPartition == NULL)
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_SELECT_NO_PARTITION);
|
2015-07-19 17:33:29 +00:00
|
|
|
else
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_PARTITION, CurrentPartition);
|
2015-07-19 17:33:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
lValue = wcstol(argv[2], &endptr, 10);
|
|
|
|
if (((lValue == 0) && (endptr == argv[2])) ||
|
|
|
|
(lValue < 0))
|
2015-07-19 17:33:29 +00:00
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2015-07-19 17:33:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
Entry = CurrentDisk->PrimaryPartListHead.Flink;
|
|
|
|
while (Entry != &CurrentDisk->PrimaryPartListHead)
|
|
|
|
{
|
|
|
|
PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
|
|
|
|
|
|
|
|
if (PartEntry->PartitionType != 0)
|
|
|
|
{
|
|
|
|
if (PartNumber == (ULONG)lValue)
|
|
|
|
{
|
|
|
|
CurrentPartition = PartEntry;
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_PARTITION, PartNumber);
|
2015-07-20 19:17:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-19 17:33:29 +00:00
|
|
|
|
2015-07-20 19:17:06 +00:00
|
|
|
PartNumber++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entry = CurrentDisk->LogicalPartListHead.Flink;
|
|
|
|
while (Entry != &CurrentDisk->LogicalPartListHead)
|
|
|
|
{
|
|
|
|
PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
|
|
|
|
|
|
|
|
if (PartEntry->PartitionType != 0)
|
|
|
|
{
|
|
|
|
if (PartNumber == (ULONG)lValue)
|
|
|
|
{
|
|
|
|
CurrentPartition = PartEntry;
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_PARTITION, PartNumber);
|
2015-07-20 19:17:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PartNumber++;
|
|
|
|
}
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
2015-07-19 17:33:29 +00:00
|
|
|
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_SELECT_PARTITION_INVALID);
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
select_main(
|
|
|
|
INT argc,
|
|
|
|
LPWSTR *argv)
|
|
|
|
{
|
|
|
|
/* gets the first word from the string */
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_HELP_CMD_SELECT);
|
2015-07-19 17:33:29 +00:00
|
|
|
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
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdOut, IDS_HELP_CMD_SELECT);
|
2015-07-19 17:33:29 +00:00
|
|
|
|
2011-09-24 10:33:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|