Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452/* * 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. * PROGRAMMERS: Lee Schroeder */
#include "diskpart.h"
#define NDEBUG#include <debug.h>
/* FUNCTIONS ******************************************************************/
staticVOIDPrintSize( _In_ ULONGLONG ullSize, _Out_ PWSTR pszOutBuffer, _In_ ULONG ulOutBufferSize){ WCHAR szUnitBuffer[8]; INT nUnitId;
if (ullSize >= SIZE_10TB) /* 10 TB */ { ullSize = RoundingDivide(ullSize, SIZE_1TB); nUnitId = IDS_UNIT_TB; } else if (ullSize >= SIZE_10GB) /* 10 GB */ { ullSize = RoundingDivide(ullSize, SIZE_1GB); nUnitId = IDS_UNIT_GB; } else if (ullSize >= SIZE_10MB) /* 10 MB */ { ullSize = RoundingDivide(ullSize, SIZE_1MB); nUnitId = IDS_UNIT_MB; } else if (ullSize >= SIZE_10KB) /* 10 KB */ { ullSize = RoundingDivide(ullSize, SIZE_1KB); nUnitId = IDS_UNIT_KB; } else { nUnitId = IDS_UNIT_B; }
LoadStringW(GetModuleHandle(NULL), nUnitId, szUnitBuffer, ARRAYSIZE(szUnitBuffer));
swprintf(pszOutBuffer, L"%4I64u %-2s", ullSize, szUnitBuffer); StringCchPrintfW(pszOutBuffer, ulOutBufferSize, L"%4I64u %-2s", ullSize, szUnitBuffer);}
staticULONGLONGGetFreeDiskSize( _In_ PDISKENTRY DiskEntry){ ULONGLONG SectorCount; PLIST_ENTRY Entry; PPARTENTRY PartEntry;
if (DiskEntry->PartitionStyle == PARTITION_STYLE_MBR) { SectorCount = DiskEntry->EndSector.QuadPart - DiskEntry->StartSector.QuadPart + 1;
Entry = DiskEntry->PrimaryPartListHead.Flink; while (Entry != &DiskEntry->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if ((PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED) && !IsContainerPartition(PartEntry->Mbr.PartitionType)) { SectorCount -= PartEntry->SectorCount.QuadPart; }
Entry = Entry->Flink; }
Entry = DiskEntry->LogicalPartListHead.Flink; while (Entry != &DiskEntry->LogicalPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED) { SectorCount -= PartEntry->SectorCount.QuadPart; }
Entry = Entry->Flink; } } else if (DiskEntry->PartitionStyle == PARTITION_STYLE_GPT) { SectorCount = DiskEntry->EndSector.QuadPart - DiskEntry->StartSector.QuadPart + 1;
Entry = DiskEntry->PrimaryPartListHead.Flink; while (Entry != &DiskEntry->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID)) { SectorCount -= PartEntry->SectorCount.QuadPart; }
Entry = Entry->Flink; } } else { SectorCount = DiskEntry->SectorCount.QuadPart; }
return SectorCount * DiskEntry->BytesPerSector;}
VOIDPrintDisk( _In_ PDISKENTRY DiskEntry){ WCHAR szDiskSizeBuffer[8]; WCHAR szFreeSizeBuffer[8]; WCHAR szBuffer[40]; ULONGLONG DiskSize; ULONGLONG FreeSize;
DiskSize = DiskEntry->SectorCount.QuadPart * (ULONGLONG)DiskEntry->BytesPerSector; PrintSize(DiskSize, szDiskSizeBuffer, ARRAYSIZE(szDiskSizeBuffer));
FreeSize = GetFreeDiskSize(DiskEntry); PrintSize(FreeSize, szFreeSizeBuffer, ARRAYSIZE(szFreeSizeBuffer));
LoadStringW(GetModuleHandle(NULL), IDS_STATUS_ONLINE, szBuffer, ARRAYSIZE(szBuffer));
ConResPrintf(StdOut, IDS_LIST_DISK_FORMAT, (CurrentDisk == DiskEntry) ? L'*' : L' ', DiskEntry->DiskNumber, szBuffer, szDiskSizeBuffer, szFreeSizeBuffer, L" ", (DiskEntry->PartitionStyle == PARTITION_STYLE_GPT) ? L"*" : L" ");}
EXIT_CODEListDisk( _In_ INT argc, _In_ PWSTR *argv){ PLIST_ENTRY Entry; PDISKENTRY DiskEntry;
/* Header labels */ ConPuts(StdOut, L"\n"); ConResPuts(StdOut, IDS_LIST_DISK_HEAD); ConResPuts(StdOut, IDS_LIST_DISK_LINE);
Entry = DiskListHead.Flink; while (Entry != &DiskListHead) { DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
PrintDisk(DiskEntry);
Entry = Entry->Flink; }
ConPuts(StdOut, L"\n\n");
return EXIT_SUCCESS;}
EXIT_CODEListPartition( _In_ INT argc, _In_ PWSTR *argv){ PLIST_ENTRY Entry; PPARTENTRY PartEntry; ULONGLONG PartSize; ULONGLONG PartOffset; ULONG PartNumber = 1; BOOL bPartitionFound = FALSE; WCHAR szPartitionTypeBuffer[40]; WCHAR szSizeBuffer[8]; WCHAR szOffsetBuffer[8]; INT nPartitionType;
if (CurrentDisk == NULL) { ConResPuts(StdOut, IDS_LIST_PARTITION_NO_DISK); return EXIT_SUCCESS; }
if (CurrentDisk->PartitionStyle == PARTITION_STYLE_MBR) { Entry = CurrentDisk->PrimaryPartListHead.Flink; while (Entry != &CurrentDisk->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED) bPartitionFound = TRUE;
Entry = Entry->Flink; } } else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT) { Entry = CurrentDisk->PrimaryPartListHead.Flink; while (Entry != &CurrentDisk->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID)) bPartitionFound = TRUE;
Entry = Entry->Flink; } }
if (bPartitionFound == FALSE) { ConPuts(StdOut, L"\n"); ConResPuts(StdOut, IDS_LIST_PARTITION_NONE); ConPuts(StdOut, L"\n"); return EXIT_SUCCESS; }
/* Header labels */ ConPuts(StdOut, L"\n"); ConResPuts(StdOut, IDS_LIST_PARTITION_HEAD); ConResPuts(StdOut, IDS_LIST_PARTITION_LINE);
if (CurrentDisk->PartitionStyle == PARTITION_STYLE_MBR) { Entry = CurrentDisk->PrimaryPartListHead.Flink; while (Entry != &CurrentDisk->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED) { PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector; PrintSize(PartSize, szSizeBuffer, ARRAYSIZE(szSizeBuffer));
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector; PrintSize(PartOffset, szOffsetBuffer, ARRAYSIZE(szOffsetBuffer));
LoadStringW(GetModuleHandle(NULL), IsContainerPartition(PartEntry->Mbr.PartitionType) ? IDS_PARTITION_TYPE_EXTENDED : IDS_PARTITION_TYPE_PRIMARY, szPartitionTypeBuffer, ARRAYSIZE(szPartitionTypeBuffer));
ConResPrintf(StdOut, IDS_LIST_PARTITION_FORMAT, (CurrentPartition == PartEntry) ? L'*' : L' ', PartNumber++, szPartitionTypeBuffer, szSizeBuffer, szOffsetBuffer); }
Entry = Entry->Flink; }
Entry = CurrentDisk->LogicalPartListHead.Flink; while (Entry != &CurrentDisk->LogicalPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED) { PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector; PrintSize(PartSize, szSizeBuffer, ARRAYSIZE(szSizeBuffer));
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector; PrintSize(PartOffset, szOffsetBuffer, ARRAYSIZE(szOffsetBuffer));
LoadStringW(GetModuleHandle(NULL), IDS_PARTITION_TYPE_LOGICAL, szPartitionTypeBuffer, ARRAYSIZE(szPartitionTypeBuffer)); ConResPrintf(StdOut, IDS_LIST_PARTITION_FORMAT, (CurrentPartition == PartEntry) ? L'*' : L' ', PartNumber++, szPartitionTypeBuffer, szSizeBuffer, szOffsetBuffer); }
Entry = Entry->Flink; } } else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT) { Entry = CurrentDisk->PrimaryPartListHead.Flink; while (Entry != &CurrentDisk->PrimaryPartListHead) { PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID)) { PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector; PrintSize(PartSize, szSizeBuffer, ARRAYSIZE(szSizeBuffer));
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector; PrintSize(PartOffset, szOffsetBuffer, ARRAYSIZE(szOffsetBuffer));
if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID)) { nPartitionType = IDS_PARTITION_TYPE_UNUSED; } else if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_BASIC_DATA_GUID)) { nPartitionType = IDS_PARTITION_TYPE_PRIMARY; } else if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_SYSTEM_GUID)) { nPartitionType = IDS_PARTITION_TYPE_SYSTEM; } else if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_MSFT_RESERVED_GUID)) { nPartitionType = IDS_PARTITION_TYPE_RESERVED; } else { nPartitionType = IDS_PARTITION_TYPE_UNKNOWN; }
LoadStringW(GetModuleHandle(NULL), nPartitionType, szPartitionTypeBuffer, ARRAYSIZE(szPartitionTypeBuffer));
ConResPrintf(StdOut, IDS_LIST_PARTITION_FORMAT, (CurrentPartition == PartEntry) ? L'*' : L' ', PartNumber++, szPartitionTypeBuffer, szSizeBuffer, szOffsetBuffer); }
Entry = Entry->Flink; } }
ConPuts(StdOut, L"\n");
return EXIT_SUCCESS;}
VOIDPrintVolume( _In_ PVOLENTRY VolumeEntry){ WCHAR szVolumeTypeBuffer[30]; WCHAR szInfoBuffer[16]; WCHAR szSizeBuffer[8]; INT nVolumeType;
switch (VolumeEntry->VolumeType) { case VOLUME_TYPE_CDROM: nVolumeType = IDS_VOLUME_TYPE_DVD; break;
case VOLUME_TYPE_PARTITION: nVolumeType = IDS_VOLUME_TYPE_PARTITION; break;
case VOLUME_TYPE_REMOVABLE: nVolumeType = IDS_VOLUME_TYPE_REMOVABLE; break;
case VOLUME_TYPE_UNKNOWN: default: nVolumeType = IDS_VOLUME_TYPE_UNKNOWN; break; }
LoadStringW(GetModuleHandle(NULL), nVolumeType, szVolumeTypeBuffer, ARRAYSIZE(szVolumeTypeBuffer));
PrintSize(VolumeEntry->Size.QuadPart, szSizeBuffer, ARRAYSIZE(szSizeBuffer));
szInfoBuffer[0] = UNICODE_NULL; if (VolumeEntry->IsSystem) LoadStringW(GetModuleHandle(NULL), IDS_INFO_SYSTEM, szInfoBuffer, ARRAYSIZE(szInfoBuffer)); else if (VolumeEntry->IsBoot) LoadStringW(GetModuleHandle(NULL), IDS_INFO_BOOT, szInfoBuffer, ARRAYSIZE(szInfoBuffer));
ConResPrintf(StdOut, IDS_LIST_VOLUME_FORMAT, (CurrentVolume == VolumeEntry) ? L'*' : L' ', VolumeEntry->VolumeNumber, VolumeEntry->DriveLetter, (VolumeEntry->pszLabel) ? VolumeEntry->pszLabel : L"", (VolumeEntry->pszFilesystem) ? VolumeEntry->pszFilesystem : L"", szVolumeTypeBuffer, szSizeBuffer, L"", szInfoBuffer);}
EXIT_CODEListVolume( _In_ INT argc, _In_ PWSTR *argv){ PLIST_ENTRY Entry; PVOLENTRY VolumeEntry;
ConPuts(StdOut, L"\n"); ConResPuts(StdOut, IDS_LIST_VOLUME_HEAD); ConResPuts(StdOut, IDS_LIST_VOLUME_LINE);
Entry = VolumeListHead.Flink; while (Entry != &VolumeListHead) { VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
PrintVolume(VolumeEntry);
Entry = Entry->Flink; }
ConPuts(StdOut, L"\n");
return EXIT_SUCCESS;}
EXIT_CODEListVirtualDisk( _In_ INT argc, _In_ PWSTR *argv){ ConPuts(StdOut, L"The LIST VDISK command is not implemented yet!\n"); return EXIT_SUCCESS;}