2011-09-24 10:33:33 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS DiskPart
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: base/system/diskpart/detail.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"
|
|
|
|
|
2022-03-27 22:25:34 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2022-05-29 15:32:34 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
IsDiskInVolume(
|
|
|
|
_In_ PVOLENTRY VolumeEntry,
|
|
|
|
_In_ PDISKENTRY DiskEntry)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
if ((VolumeEntry == NULL) ||
|
|
|
|
(VolumeEntry->pExtents == NULL) ||
|
|
|
|
(DiskEntry == NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
|
|
|
|
{
|
|
|
|
if (VolumeEntry->pExtents->Extents[i].DiskNumber == DiskEntry->DiskNumber)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
IsPartitionInVolume(
|
|
|
|
_In_ PVOLENTRY VolumeEntry,
|
|
|
|
_In_ PPARTENTRY PartEntry)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
if ((VolumeEntry == NULL) ||
|
|
|
|
(VolumeEntry->pExtents == NULL) ||
|
|
|
|
(PartEntry == NULL) ||
|
|
|
|
(PartEntry->DiskEntry == NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
|
|
|
|
{
|
|
|
|
if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
|
|
|
|
{
|
|
|
|
if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
|
|
|
|
(VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-15 10:27:53 +00:00
|
|
|
BOOL
|
2022-03-27 22:25:34 +00:00
|
|
|
DetailDisk(
|
2022-05-29 15:32:34 +00:00
|
|
|
_In_ INT argc,
|
|
|
|
_In_ PWSTR *argv)
|
2011-09-24 10:33:33 +00:00
|
|
|
{
|
2022-05-29 15:32:34 +00:00
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PVOLENTRY VolumeEntry;
|
|
|
|
BOOL bPrintHeader = TRUE;
|
|
|
|
|
2022-03-27 22:25:34 +00:00
|
|
|
DPRINT("DetailDisk()\n");
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrentDisk == NULL)
|
|
|
|
{
|
|
|
|
ConResPuts(StdOut, IDS_SELECT_NO_DISK);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Print more disk details */
|
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_INFO_DISK_ID, CurrentDisk->LayoutBuffer->Signature);
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_INFO_PATH, CurrentDisk->PathId);
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_INFO_TARGET, CurrentDisk->TargetId);
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_INFO_LUN_ID, CurrentDisk->Lun);
|
2022-05-29 15:32:34 +00:00
|
|
|
|
|
|
|
Entry = VolumeListHead.Flink;
|
|
|
|
while (Entry != &VolumeListHead)
|
|
|
|
{
|
|
|
|
VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
|
|
|
|
|
|
|
|
if (IsDiskInVolume(VolumeEntry, CurrentDisk))
|
|
|
|
{
|
|
|
|
if (bPrintHeader)
|
|
|
|
{
|
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPuts(StdOut, IDS_LIST_VOLUME_HEAD);
|
|
|
|
ConResPuts(StdOut, IDS_LIST_VOLUME_LINE);
|
|
|
|
bPrintHeader = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintVolume(VolumeEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
2022-03-27 22:25:34 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
2022-05-15 10:27:53 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-15 10:27:53 +00:00
|
|
|
BOOL
|
2022-03-27 22:25:34 +00:00
|
|
|
DetailPartition(
|
2022-05-29 15:32:34 +00:00
|
|
|
_In_ INT argc,
|
|
|
|
_In_ PWSTR *argv)
|
2022-03-27 22:25:34 +00:00
|
|
|
{
|
|
|
|
PPARTENTRY PartEntry;
|
|
|
|
ULONGLONG PartOffset;
|
2022-05-29 15:32:34 +00:00
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PVOLENTRY VolumeEntry;
|
|
|
|
BOOL bVolumeFound = FALSE, bPrintHeader = TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
|
|
|
|
DPRINT("DetailPartition()\n");
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrentDisk == NULL)
|
|
|
|
{
|
|
|
|
ConResPuts(StdOut, IDS_SELECT_PARTITION_NO_DISK);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrentPartition == NULL)
|
|
|
|
{
|
|
|
|
ConResPuts(StdOut, IDS_SELECT_NO_PARTITION);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PartEntry = CurrentPartition;
|
|
|
|
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
|
|
|
|
|
|
|
|
/* TODO: Print more partition details */
|
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_PARTITION_NUMBER, PartEntry->PartitionNumber);
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_PARTITION_TYPE, PartEntry->PartitionType);
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_PARTITION_HIDDEN, "");
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_PARTITION_ACTIVE, PartEntry->BootIndicator ? L"Yes" : L"No");
|
|
|
|
ConResPrintf(StdOut, IDS_DETAIL_PARTITION_OFFSET, PartOffset);
|
2022-05-29 15:32:34 +00:00
|
|
|
|
|
|
|
Entry = VolumeListHead.Flink;
|
|
|
|
while (Entry != &VolumeListHead)
|
|
|
|
{
|
|
|
|
VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
|
|
|
|
|
|
|
|
if (IsPartitionInVolume(VolumeEntry, CurrentPartition))
|
|
|
|
{
|
|
|
|
if (bPrintHeader)
|
|
|
|
{
|
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPuts(StdOut, IDS_LIST_VOLUME_HEAD);
|
|
|
|
ConResPuts(StdOut, IDS_LIST_VOLUME_LINE);
|
|
|
|
bPrintHeader = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintVolume(VolumeEntry);
|
|
|
|
bVolumeFound = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bVolumeFound == FALSE)
|
2022-05-29 23:09:08 +00:00
|
|
|
ConResPuts(StdOut, IDS_DETAIL_NO_VOLUME);
|
2022-05-29 15:32:34 +00:00
|
|
|
|
2022-03-27 22:25:34 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
2022-05-15 10:27:53 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-15 10:27:53 +00:00
|
|
|
BOOL
|
2022-03-27 22:25:34 +00:00
|
|
|
DetailVolume(
|
2022-05-29 15:32:34 +00:00
|
|
|
_In_ INT argc,
|
|
|
|
_In_ PWSTR *argv)
|
2022-03-27 22:25:34 +00:00
|
|
|
{
|
2022-05-29 15:32:34 +00:00
|
|
|
PDISKENTRY DiskEntry;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
BOOL bDiskFound = FALSE, bPrintHeader = TRUE;
|
|
|
|
|
2022-03-27 22:25:34 +00:00
|
|
|
DPRINT("DetailVolume()\n");
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
{
|
|
|
|
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
|
2022-05-15 10:27:53 +00:00
|
|
|
return TRUE;
|
2022-03-27 22:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrentVolume == NULL)
|
|
|
|
{
|
|
|
|
ConResPuts(StdOut, IDS_SELECT_NO_VOLUME);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-05-29 15:32:34 +00:00
|
|
|
|
|
|
|
Entry = DiskListHead.Flink;
|
|
|
|
while (Entry != &DiskListHead)
|
|
|
|
{
|
|
|
|
DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
|
|
|
|
|
|
|
|
if (IsDiskInVolume(CurrentVolume, DiskEntry))
|
|
|
|
{
|
|
|
|
if (bPrintHeader)
|
|
|
|
{
|
|
|
|
ConPuts(StdOut, L"\n");
|
|
|
|
ConResPuts(StdOut, IDS_LIST_DISK_HEAD);
|
|
|
|
ConResPuts(StdOut, IDS_LIST_DISK_LINE);
|
|
|
|
bPrintHeader = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintDisk(DiskEntry);
|
|
|
|
bDiskFound = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bDiskFound == FALSE)
|
2022-05-29 23:09:08 +00:00
|
|
|
ConResPuts(StdOut, IDS_DETAIL_NO_DISKS);
|
2022-05-29 15:32:34 +00:00
|
|
|
|
|
|
|
/* TODO: Print more volume details */
|
|
|
|
|
|
|
|
ConPuts(StdOut, L"\n");
|
2022-03-27 22:25:34 +00:00
|
|
|
|
2011-09-24 10:33:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|