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
|
|
|
|
2022-05-15 10:27:53 +00:00
|
|
|
BOOL
|
2015-07-19 17:33:29 +00:00
|
|
|
SelectDisk(
|
|
|
|
INT argc,
|
2022-05-15 10:27:53 +00:00
|
|
|
PWSTR *argv)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PDISKENTRY DiskEntry;
|
2022-03-27 22:04:24 +00:00
|
|
|
ULONG ulValue;
|
2015-07-19 17:33:29 +00:00
|
|
|
|
|
|
|
DPRINT("Select Disk()\n");
|
|
|
|
|
|
|
|
if (argc > 3)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 22:04:24 +00:00
|
|
|
if (!IsDecString(argv[2]))
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulValue = wcstoul(argv[2], NULL, 10);
|
|
|
|
if ((ulValue == 0) && (errno == ERANGE))
|
2015-07-19 17:33:29 +00:00
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-03-27 22:04:24 +00:00
|
|
|
if (DiskEntry->DiskNumber == ulValue)
|
2015-07-20 19:17:06 +00:00
|
|
|
{
|
|
|
|
CurrentDisk = DiskEntry;
|
|
|
|
CurrentPartition = NULL;
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_DISK, CurrentDisk->DiskNumber);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-20 19:17:06 +00:00
|
|
|
}
|
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);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-15 10:27:53 +00:00
|
|
|
BOOL
|
2015-07-19 17:33:29 +00:00
|
|
|
SelectPartition(
|
|
|
|
INT argc,
|
2022-05-15 10:27:53 +00:00
|
|
|
PWSTR *argv)
|
2015-07-19 17:33:29 +00:00
|
|
|
{
|
2015-07-20 19:17:06 +00:00
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PPARTENTRY PartEntry;
|
2022-03-27 22:04:24 +00:00
|
|
|
ULONG ulValue;
|
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);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-20 19:17:06 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 22:04:24 +00:00
|
|
|
if (!IsDecString(argv[2]))
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulValue = wcstoul(argv[2], NULL, 10);
|
|
|
|
if ((ulValue == 0) && (errno == ERANGE))
|
2015-07-19 17:33:29 +00:00
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2022-03-27 22:04:24 +00:00
|
|
|
if (PartNumber == ulValue)
|
2015-07-20 19:17:06 +00:00
|
|
|
{
|
|
|
|
CurrentPartition = PartEntry;
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_PARTITION, PartNumber);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-20 19:17:06 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2022-03-27 22:04:24 +00:00
|
|
|
if (PartNumber == ulValue)
|
2015-07-20 19:17:06 +00:00
|
|
|
{
|
|
|
|
CurrentPartition = PartEntry;
|
2016-10-07 22:50:32 +00:00
|
|
|
ConResPrintf(StdOut, IDS_SELECT_PARTITION, PartNumber);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-20 19:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2015-07-19 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-15 10:27:53 +00:00
|
|
|
BOOL
|
2022-03-26 14:18:08 +00:00
|
|
|
SelectVolume(
|
|
|
|
INT argc,
|
2022-05-15 10:27:53 +00:00
|
|
|
PWSTR *argv)
|
2022-03-26 14:18:08 +00:00
|
|
|
{
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PVOLENTRY VolumeEntry;
|
2022-03-27 22:04:24 +00:00
|
|
|
ULONG ulValue;
|
2022-03-26 14:18:08 +00:00
|
|
|
|
|
|
|
DPRINT("SelectVolume()\n");
|
|
|
|
|
|
|
|
if (argc > 3)
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-26 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
if (CurrentDisk == NULL)
|
|
|
|
ConResPuts(StdOut, IDS_SELECT_NO_VOLUME);
|
|
|
|
else
|
|
|
|
ConResPrintf(StdOut, IDS_SELECT_VOLUME, CurrentVolume->VolumeNumber);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-26 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 22:04:24 +00:00
|
|
|
if (!IsDecString(argv[2]))
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulValue = wcstoul(argv[2], NULL, 10);
|
|
|
|
if ((ulValue == 0) && (errno == ERANGE))
|
2022-03-26 14:18:08 +00:00
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-26 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CurrentVolume = NULL;
|
|
|
|
|
|
|
|
Entry = VolumeListHead.Flink;
|
|
|
|
while (Entry != &VolumeListHead)
|
|
|
|
{
|
|
|
|
VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
|
|
|
|
|
2022-03-27 22:04:24 +00:00
|
|
|
if (VolumeEntry->VolumeNumber == ulValue)
|
2022-03-26 14:18:08 +00:00
|
|
|
{
|
|
|
|
CurrentVolume = VolumeEntry;
|
|
|
|
ConResPrintf(StdOut, IDS_SELECT_VOLUME, CurrentVolume->VolumeNumber);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-26 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConResPuts(StdErr, IDS_SELECT_VOLUME_INVALID);
|
2011-09-24 10:33:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|