1 /* 2 * PROJECT: ReactOS DiskPart 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: base/system/diskpart/list.c 5 * PURPOSE: Manages all the partitions of the OS in an interactive way. 6 * PROGRAMMERS: Lee Schroeder 7 */ 8 9 #include "diskpart.h" 10 11 #define NDEBUG 12 #include <debug.h> 13 14 /* FUNCTIONS ******************************************************************/ 15 16 VOID 17 PrintDisk( 18 _In_ PDISKENTRY DiskEntry) 19 { 20 ULONGLONG DiskSize; 21 ULONGLONG FreeSize; 22 LPWSTR lpSizeUnit; 23 LPWSTR lpFreeUnit; 24 25 DiskSize = DiskEntry->SectorCount.QuadPart * 26 (ULONGLONG)DiskEntry->BytesPerSector; 27 28 if (DiskSize >= 10737418240) /* 10 GB */ 29 { 30 DiskSize = RoundingDivide(DiskSize, 1073741824); 31 lpSizeUnit = L"GB"; 32 } 33 else 34 { 35 DiskSize = RoundingDivide(DiskSize, 1048576); 36 if (DiskSize == 0) 37 DiskSize = 1; 38 lpSizeUnit = L"MB"; 39 } 40 41 /* FIXME */ 42 FreeSize = 0; 43 lpFreeUnit = L"B"; 44 45 ConResPrintf(StdOut, IDS_LIST_DISK_FORMAT, 46 (CurrentDisk == DiskEntry) ? L'*' : L' ', 47 DiskEntry->DiskNumber, 48 L"Online", 49 DiskSize, 50 lpSizeUnit, 51 FreeSize, 52 lpFreeUnit, 53 L" ", 54 L" "); 55 } 56 57 58 BOOL 59 ListDisk( 60 INT argc, 61 PWSTR *argv) 62 { 63 PLIST_ENTRY Entry; 64 PDISKENTRY DiskEntry; 65 66 /* Header labels */ 67 ConPuts(StdOut, L"\n"); 68 ConResPuts(StdOut, IDS_LIST_DISK_HEAD); 69 ConResPuts(StdOut, IDS_LIST_DISK_LINE); 70 71 Entry = DiskListHead.Flink; 72 while (Entry != &DiskListHead) 73 { 74 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry); 75 76 PrintDisk(DiskEntry); 77 78 Entry = Entry->Flink; 79 } 80 81 ConPuts(StdOut, L"\n\n"); 82 83 return TRUE; 84 } 85 86 87 BOOL 88 ListPartition( 89 INT argc, 90 PWSTR *argv) 91 { 92 PLIST_ENTRY Entry; 93 PPARTENTRY PartEntry; 94 ULONGLONG PartSize; 95 ULONGLONG PartOffset; 96 LPWSTR lpSizeUnit; 97 LPWSTR lpOffsetUnit; 98 ULONG PartNumber = 1; 99 100 if (CurrentDisk == NULL) 101 { 102 ConResPuts(StdOut, IDS_LIST_PARTITION_NO_DISK); 103 return TRUE; 104 } 105 106 /* Header labels */ 107 ConPuts(StdOut, L"\n"); 108 ConResPuts(StdOut, IDS_LIST_PARTITION_HEAD); 109 ConResPuts(StdOut, IDS_LIST_PARTITION_LINE); 110 111 Entry = CurrentDisk->PrimaryPartListHead.Flink; 112 while (Entry != &CurrentDisk->PrimaryPartListHead) 113 { 114 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); 115 116 if (PartEntry->PartitionType != 0) 117 { 118 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector; 119 120 if (PartSize >= 10737418240) /* 10 GB */ 121 { 122 PartSize = RoundingDivide(PartSize, 1073741824); 123 lpSizeUnit = L"GB"; 124 } 125 else if (PartSize >= 10485760) /* 10 MB */ 126 { 127 PartSize = RoundingDivide(PartSize, 1048576); 128 lpSizeUnit = L"MB"; 129 } 130 else 131 { 132 PartSize = RoundingDivide(PartSize, 1024); 133 lpSizeUnit = L"KB"; 134 } 135 136 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector; 137 138 if (PartOffset >= 10737418240) /* 10 GB */ 139 { 140 PartOffset = RoundingDivide(PartOffset, 1073741824); 141 lpOffsetUnit = L"GB"; 142 } 143 else if (PartOffset >= 10485760) /* 10 MB */ 144 { 145 PartOffset = RoundingDivide(PartOffset, 1048576); 146 lpOffsetUnit = L"MB"; 147 } 148 else 149 { 150 PartOffset = RoundingDivide(PartOffset, 1024); 151 lpOffsetUnit = L"KB"; 152 } 153 154 ConResPrintf(StdOut, IDS_LIST_PARTITION_FORMAT, 155 (CurrentPartition == PartEntry) ? L'*' : L' ', 156 PartNumber++, 157 IsContainerPartition(PartEntry->PartitionType) ? L"Extended" : L"Primary", 158 PartSize, 159 lpSizeUnit, 160 PartOffset, 161 lpOffsetUnit); 162 } 163 164 Entry = Entry->Flink; 165 } 166 167 Entry = CurrentDisk->LogicalPartListHead.Flink; 168 while (Entry != &CurrentDisk->LogicalPartListHead) 169 { 170 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); 171 172 if (PartEntry->PartitionType != 0) 173 { 174 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector; 175 176 if (PartSize >= 10737418240) /* 10 GB */ 177 { 178 PartSize = RoundingDivide(PartSize, 1073741824); 179 lpSizeUnit = L"GB"; 180 } 181 else if (PartSize >= 10485760) /* 10 MB */ 182 { 183 PartSize = RoundingDivide(PartSize, 1048576); 184 lpSizeUnit = L"MB"; 185 } 186 else 187 { 188 PartSize = RoundingDivide(PartSize, 1024); 189 lpSizeUnit = L"KB"; 190 } 191 192 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector; 193 194 if (PartOffset >= 10737418240) /* 10 GB */ 195 { 196 PartOffset = RoundingDivide(PartOffset, 1073741824); 197 lpOffsetUnit = L"GB"; 198 } 199 else if (PartOffset >= 10485760) /* 10 MB */ 200 { 201 PartOffset = RoundingDivide(PartOffset, 1048576); 202 lpOffsetUnit = L"MB"; 203 } 204 else 205 { 206 PartOffset = RoundingDivide(PartOffset, 1024); 207 lpOffsetUnit = L"KB"; 208 } 209 210 ConResPrintf(StdOut, IDS_LIST_PARTITION_FORMAT, 211 (CurrentPartition == PartEntry) ? L'*' : L' ', 212 PartNumber++, 213 L"Logical", 214 PartSize, 215 lpSizeUnit, 216 PartOffset, 217 lpOffsetUnit); 218 } 219 220 Entry = Entry->Flink; 221 } 222 223 ConPuts(StdOut, L"\n"); 224 225 return TRUE; 226 } 227 228 229 VOID 230 PrintVolume( 231 _In_ PVOLENTRY VolumeEntry) 232 { 233 ULONGLONG VolumeSize; 234 PWSTR pszSizeUnit; 235 PWSTR pszVolumeType; 236 237 VolumeSize = VolumeEntry->Size.QuadPart; 238 if (VolumeSize >= 10737418240) /* 10 GB */ 239 { 240 VolumeSize = RoundingDivide(VolumeSize, 1073741824); 241 pszSizeUnit = L"GB"; 242 } 243 else if (VolumeSize >= 10485760) /* 10 MB */ 244 { 245 VolumeSize = RoundingDivide(VolumeSize, 1048576); 246 pszSizeUnit = L"MB"; 247 } 248 else 249 { 250 VolumeSize = RoundingDivide(VolumeSize, 1024); 251 pszSizeUnit = L"KB"; 252 } 253 switch (VolumeEntry->VolumeType) 254 { 255 case VOLUME_TYPE_CDROM: 256 pszVolumeType = L"DVD"; 257 break; 258 case VOLUME_TYPE_PARTITION: 259 pszVolumeType = L"Partition"; 260 break; 261 case VOLUME_TYPE_REMOVABLE: 262 pszVolumeType = L"Removable"; 263 break; 264 case VOLUME_TYPE_UNKNOWN: 265 default: 266 pszVolumeType = L"Unknown"; 267 break; 268 } 269 270 ConResPrintf(StdOut, IDS_LIST_VOLUME_FORMAT, 271 (CurrentVolume == VolumeEntry) ? L'*' : L' ', 272 VolumeEntry->VolumeNumber, 273 VolumeEntry->DriveLetter, 274 (VolumeEntry->pszLabel) ? VolumeEntry->pszLabel : L"", 275 (VolumeEntry->pszFilesystem) ? VolumeEntry->pszFilesystem : L"", 276 pszVolumeType, 277 VolumeSize, pszSizeUnit); 278 } 279 280 281 BOOL 282 ListVolume( 283 INT argc, 284 PWSTR *argv) 285 { 286 PLIST_ENTRY Entry; 287 PVOLENTRY VolumeEntry; 288 289 ConPuts(StdOut, L"\n"); 290 ConResPuts(StdOut, IDS_LIST_VOLUME_HEAD); 291 ConResPuts(StdOut, IDS_LIST_VOLUME_LINE); 292 293 Entry = VolumeListHead.Flink; 294 while (Entry != &VolumeListHead) 295 { 296 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry); 297 298 PrintVolume(VolumeEntry); 299 300 Entry = Entry->Flink; 301 } 302 303 ConPuts(StdOut, L"\n"); 304 305 return TRUE; 306 } 307 308 309 BOOL 310 ListVirtualDisk( 311 INT argc, 312 PWSTR *argv) 313 { 314 ConPuts(StdOut, L"ListVirtualDisk()!\n"); 315 return TRUE; 316 } 317