ReactOS 0.4.17-dev-1190-g4c812f4
partlist.c File Reference
#include "diskpart.h"
#include <debug.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for partlist.c:

Go to the source code of this file.

Classes

struct  _PARTITION
 
struct  _PARTITION_SECTOR
 

Macros

#define NDEBUG
 
#define InsertAscendingList(ListHead, NewEntry, Type, ListEntryField, SortField)
 
#define PARTITION_LINUX   0x83
 
#define PARTITION_TBL_SIZE   4
 
#define MBR_MAGIC   0xAA55
 
#define ROOT_NAME   L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"
 

Typedefs

typedef struct _PARTITION PARTITION
 
typedef struct _PARTITION * PPARTITION
 
typedef struct _PARTITION_SECTOR PARTITION_SECTOR
 
typedef struct _PARTITION_SECTOR * PPARTITION_SECTOR
 

Functions

ULONGLONG AlignDown (_In_ ULONGLONG Value, _In_ ULONG Alignment)
 
static VOID GetDriverName (PDISKENTRY DiskEntry)
 
static NTSTATUS NTAPI DiskIdentifierQueryRoutine (PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
 
static NTSTATUS NTAPI DiskConfigurationDataQueryRoutine (PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
 
static NTSTATUS NTAPI SystemConfigurationDataQueryRoutine (PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
 
static VOID EnumerateBiosDiskEntries (VOID)
 
static VOID AddMbrPartitionToDisk (ULONG DiskNumber, PDISKENTRY DiskEntry, ULONG PartitionIndex, BOOLEAN LogicalPartition)
 
static VOID AddGptPartitionToDisk (ULONG DiskNumber, PDISKENTRY DiskEntry, ULONG PartitionIndex)
 
VOID ScanForUnpartitionedMbrDiskSpace (PDISKENTRY DiskEntry)
 
VOID ScanForUnpartitionedGptDiskSpace (PDISKENTRY DiskEntry)
 
VOID ReadLayoutBuffer (_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
 
static VOID AddDiskToList (HANDLE FileHandle, ULONG DiskNumber)
 
NTSTATUS CreatePartitionList (VOID)
 
VOID DestroyPartitionList (VOID)
 
static VOID GetVolumeExtents (_In_ HANDLE VolumeHandle, _In_ PVOLENTRY VolumeEntry)
 
static VOID GetVolumeType (_In_ HANDLE VolumeHandle, _In_ PVOLENTRY VolumeEntry)
 
static VOID GetVolumeSize (_In_ HANDLE VolumeHandle, _In_ PVOLENTRY VolumeEntry)
 
static PDISKENTRY GetDiskForVolume (_In_ PVOLENTRY VolumeEntry)
 
static PPARTENTRY GetPartitionForVolume (_In_ PVOLENTRY VolumeEntry)
 
static VOID IsVolumeSystem (_In_ PVOLENTRY VolumeEntry)
 
static VOID IsVolumeBoot (_In_ PVOLENTRY VolumeEntry)
 
static VOID AddVolumeToList (ULONG ulVolumeNumber, PWSTR pszVolumeName)
 
static VOID InsertListAfter (_In_ PLIST_ENTRY ListEntry, _In_ PLIST_ENTRY EntryToInsert)
 
static VOID SortVolumeList (VOID)
 
NTSTATUS CreateVolumeList (VOID)
 
VOID DestroyVolumeList (VOID)
 
VOID UpdateVolumeInfo (_In_ PVOLENTRY VolumeEntry)
 
NTSTATUS WriteMbrPartitions (_In_ PDISKENTRY DiskEntry)
 
NTSTATUS WriteGptPartitions (_In_ PDISKENTRY DiskEntry)
 
static BOOLEAN IsEmptyLayoutEntry (IN PPARTITION_INFORMATION_EX PartitionInfo)
 
static BOOLEAN IsSamePrimaryLayoutEntry (IN PPARTITION_INFORMATION_EX PartitionInfo, IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry)
 
ULONG GetPrimaryPartitionCount (_In_ PDISKENTRY DiskEntry)
 
static ULONG GetLogicalPartitionCount (_In_ PDISKENTRY DiskEntry)
 
static BOOLEAN ReAllocateLayoutBuffer (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateMbrDiskLayout (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateGptDiskLayout (_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
 
PPARTENTRY GetPrevUnpartitionedEntry (_In_ PPARTENTRY PartEntry)
 
PPARTENTRY GetNextUnpartitionedEntry (_In_ PPARTENTRY PartEntry)
 
NTSTATUS DismountVolume (_In_ PPARTENTRY PartEntry)
 
PVOLENTRY GetVolumeFromPartition (_In_ PPARTENTRY PartEntry)
 
VOID RemoveVolume (_In_ PVOLENTRY VolumeEntry)
 

Variables

LIST_ENTRY DiskListHead
 
LIST_ENTRY BiosDiskListHead
 
LIST_ENTRY VolumeListHead
 
PDISKENTRY CurrentDisk = NULL
 
PPARTENTRY CurrentPartition = NULL
 
PVOLENTRY CurrentVolume = NULL
 

Macro Definition Documentation

◆ InsertAscendingList

#define InsertAscendingList (   ListHead,
  NewEntry,
  Type,
  ListEntryField,
  SortField 
)
Value:
{\
\
current = (ListHead)->Flink;\
while (current != (ListHead))\
{\
if (CONTAINING_RECORD(current, Type, ListEntryField)->SortField >=\
(NewEntry)->SortField)\
{\
break;\
}\
current = current->Flink;\
}\
\
InsertTailList(current, &((NewEntry)->ListEntryField));\
}
Type
Definition: Type.h:7
struct task_struct * current
Definition: linux.c:32
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Definition at line 16 of file partlist.c.

◆ MBR_MAGIC

#define MBR_MAGIC   0xAA55

Definition at line 39 of file partlist.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file partlist.c.

◆ PARTITION_LINUX

#define PARTITION_LINUX   0x83

Definition at line 35 of file partlist.c.

◆ PARTITION_TBL_SIZE

#define PARTITION_TBL_SIZE   4

Definition at line 37 of file partlist.c.

◆ ROOT_NAME

#define ROOT_NAME   L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"

Definition at line 357 of file partlist.c.

Typedef Documentation

◆ PARTITION

◆ PARTITION_SECTOR

◆ PPARTITION

◆ PPARTITION_SECTOR

Function Documentation

◆ AddDiskToList()

static VOID AddDiskToList ( HANDLE  FileHandle,
ULONG  DiskNumber 
)
static

Definition at line 1126 of file partlist.c.

1129{
1130 DISK_GEOMETRY DiskGeometry;
1131 SCSI_ADDRESS ScsiAddress;
1132 PDISKENTRY DiskEntry;
1136 PULONG Buffer;
1138 WCHAR Identifier[20];
1139 ULONG Checksum;
1141 ULONG i;
1142 PLIST_ENTRY ListEntry;
1143 PBIOSDISKENTRY BiosDiskEntry;
1144
1146 NULL,
1147 NULL,
1148 NULL,
1149 &Iosb,
1151 NULL,
1152 0,
1153 &DiskGeometry,
1154 sizeof(DISK_GEOMETRY));
1155 if (!NT_SUCCESS(Status))
1156 {
1157 return;
1158 }
1159
1160 if (DiskGeometry.MediaType != FixedMedia &&
1161 DiskGeometry.MediaType != RemovableMedia)
1162 {
1163 return;
1164 }
1165
1167 NULL,
1168 NULL,
1169 NULL,
1170 &Iosb,
1172 NULL,
1173 0,
1174 &ScsiAddress,
1175 sizeof(SCSI_ADDRESS));
1176 if (!NT_SUCCESS(Status))
1177 {
1178 return;
1179 }
1180
1181 PBYTE pBuffer = NULL;
1182
1183 pBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
1185 1024);
1186
1187 STORAGE_PROPERTY_QUERY StoragePropertyQuery;
1188 StoragePropertyQuery.PropertyId = StorageDeviceProperty;
1189 StoragePropertyQuery.QueryType = PropertyStandardQuery;
1191 NULL,
1192 NULL,
1193 NULL,
1194 &Iosb,
1196 &StoragePropertyQuery,
1197 sizeof(STORAGE_PROPERTY_QUERY),
1198 pBuffer,
1199 1024);
1200 if (!NT_SUCCESS(Status))
1201 {
1202 RtlFreeHeap(RtlGetProcessHeap(), 0, pBuffer);
1203 pBuffer = NULL;
1204 }
1205
1206
1207 Mbr = (PARTITION_SECTOR*)RtlAllocateHeap(RtlGetProcessHeap(),
1208 0,
1209 DiskGeometry.BytesPerSector);
1210 if (Mbr == NULL)
1211 {
1212 return;
1213 }
1214
1215 FileOffset.QuadPart = 0;
1217 NULL,
1218 NULL,
1219 NULL,
1220 &Iosb,
1221 (PVOID)Mbr,
1222 DiskGeometry.BytesPerSector,
1223 &FileOffset,
1224 NULL);
1225 if (!NT_SUCCESS(Status))
1226 {
1227 RtlFreeHeap(RtlGetProcessHeap(), 0, Mbr);
1228 DPRINT1("NtReadFile failed, status=%x\n", Status);
1229 return;
1230 }
1231 Signature = Mbr->Signature;
1232
1233 /* Calculate the MBR checksum */
1234 Checksum = 0;
1235 Buffer = (PULONG)Mbr;
1236 for (i = 0; i < 128; i++)
1237 {
1238 Checksum += Buffer[i];
1239 }
1240 Checksum = ~Checksum + 1;
1241
1243 L"%08x-%08x-A", Checksum, Signature);
1244 DPRINT("Identifier: %S\n", Identifier);
1245
1246 DiskEntry = RtlAllocateHeap(RtlGetProcessHeap(),
1248 sizeof(DISKENTRY));
1249 if (DiskEntry == NULL)
1250 {
1251 if (pBuffer)
1252 RtlFreeHeap(RtlGetProcessHeap(), 0, pBuffer);
1253 RtlFreeHeap(RtlGetProcessHeap(), 0, Mbr);
1254 return;
1255 }
1256
1257 if (pBuffer)
1258 {
1259 PSTORAGE_DESCRIPTOR_HEADER pDescriptorHeader;
1260
1261 pDescriptorHeader = (PSTORAGE_DESCRIPTOR_HEADER)pBuffer;
1262 DPRINT("DescriptorHeader.Size %lu\n", pDescriptorHeader->Size);
1263
1264 if (pDescriptorHeader->Size <= 1024)
1265 {
1266 PSTORAGE_DEVICE_DESCRIPTOR pDeviceDescriptor;
1267 pDeviceDescriptor = (PSTORAGE_DEVICE_DESCRIPTOR)pBuffer;
1268 DPRINT("VendorIdOffset %lu\n", pDeviceDescriptor->VendorIdOffset);
1269 DPRINT("ProductIdOffset %lu\n", pDeviceDescriptor->ProductIdOffset);
1270 DPRINT("ProductRevisionOffset %lu\n", pDeviceDescriptor->ProductRevisionOffset);
1271 DPRINT("SerialNumberOffset %lu\n", pDeviceDescriptor->SerialNumberOffset);
1272 DPRINT("BusType: %u\n", pDeviceDescriptor->BusType);
1273 if (pDeviceDescriptor->VendorIdOffset)
1274 {
1275 DPRINT("Vendor: %s\n", (PSTR)((ULONG_PTR)pBuffer + pDeviceDescriptor->VendorIdOffset));
1276 }
1277
1278 if (pDeviceDescriptor->ProductIdOffset)
1279 {
1280 DPRINT("Product: %s\n", (PSTR)((ULONG_PTR)pBuffer + pDeviceDescriptor->ProductIdOffset));
1281 }
1282
1283 INT VendorLength = 0, ProductLength = 0;
1284 PWSTR VendorBuffer = NULL, ProductBuffer = NULL;
1285
1286 if (pDeviceDescriptor->VendorIdOffset)
1287 {
1288 VendorLength = MultiByteToWideChar(437,
1289 0,
1290 (PSTR)((ULONG_PTR)pBuffer + pDeviceDescriptor->VendorIdOffset),
1291 -1,
1292 NULL,
1293 0);
1294 VendorBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
1296 VendorLength * sizeof(WCHAR));
1297 if (VendorBuffer)
1299 0,
1300 (PSTR)((ULONG_PTR)pBuffer + pDeviceDescriptor->VendorIdOffset),
1301 -1,
1302 VendorBuffer,
1303 VendorLength);
1304 }
1305
1306 if (pDeviceDescriptor->ProductIdOffset)
1307 {
1308 ProductLength = MultiByteToWideChar(437,
1309 0,
1310 (PSTR)((ULONG_PTR)pBuffer + pDeviceDescriptor->ProductIdOffset),
1311 -1,
1312 NULL,
1313 0);
1314
1315 ProductBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
1317 ProductLength * sizeof(WCHAR));
1318 if (ProductBuffer)
1320 0,
1321 (PSTR)((ULONG_PTR)pBuffer + pDeviceDescriptor->ProductIdOffset),
1322 -1,
1323 ProductBuffer,
1324 ProductLength);
1325 }
1326
1327 DiskEntry->Description = RtlAllocateHeap(RtlGetProcessHeap(),
1329 (VendorLength + ProductLength + 2) * sizeof(WCHAR));
1330 if (VendorBuffer)
1331 wcscat(DiskEntry->Description, VendorBuffer);
1332
1333 if ((VendorLength > 0) && (ProductLength > 0))
1334 wcscat(DiskEntry->Description, L" ");
1335
1336 if (ProductBuffer)
1337 wcscat(DiskEntry->Description, ProductBuffer);
1338
1339 DiskEntry->BusType = pDeviceDescriptor->BusType;
1340
1341 if (VendorBuffer)
1342 RtlFreeHeap(RtlGetProcessHeap(), 0, VendorBuffer);
1343
1344 if (ProductBuffer)
1345 RtlFreeHeap(RtlGetProcessHeap(), 0, ProductBuffer);
1346 }
1347
1348 RtlFreeHeap(RtlGetProcessHeap(), 0, pBuffer);
1349 }
1350
1351// DiskEntry->Checksum = Checksum;
1352// DiskEntry->Signature = Signature;
1353 DiskEntry->BiosFound = FALSE;
1354
1355 /* Check the disk partition style */
1356 if (Mbr->Magic != MBR_MAGIC)
1357 {
1358 DPRINT("Partition style: RAW\n");
1359 DiskEntry->PartitionStyle = PARTITION_STYLE_RAW;
1360 }
1361 else
1362 {
1363 if (Mbr->Partition[0].PartitionType == PARTITION_GPT)
1364 {
1365 DPRINT("Partition style: GPT\n");
1367 }
1368 else
1369 {
1370 DPRINT("Partition style: MBR\n");
1372 }
1373 }
1374
1375 /* Free Mbr sector buffer */
1376 RtlFreeHeap(RtlGetProcessHeap(), 0, Mbr);
1377
1378 ListEntry = BiosDiskListHead.Flink;
1379 while (ListEntry != &BiosDiskListHead)
1380 {
1381 BiosDiskEntry = CONTAINING_RECORD(ListEntry, BIOSDISKENTRY, ListEntry);
1382 /* FIXME:
1383 * Compare the size from bios and the reported size from driver.
1384 * If we have more than one disk with a zero or with the same signatur
1385 * we must create new signatures and reboot. After the reboot,
1386 * it is possible to identify the disks.
1387 */
1388 if (BiosDiskEntry->Signature == Signature &&
1389 BiosDiskEntry->Checksum == Checksum &&
1390 !BiosDiskEntry->Recognized)
1391 {
1392 if (!DiskEntry->BiosFound)
1393 {
1394 DiskEntry->BiosDiskNumber = BiosDiskEntry->DiskNumber;
1395 DiskEntry->BiosFound = TRUE;
1396 BiosDiskEntry->Recognized = TRUE;
1397 }
1398 else
1399 {
1400 }
1401 }
1402 ListEntry = ListEntry->Flink;
1403 }
1404
1405 if (!DiskEntry->BiosFound)
1406 {
1407#if 0
1408 RtlFreeHeap(ProcessHeap, 0, DiskEntry);
1409 return;
1410#else
1411 DPRINT1("WARNING: Setup could not find a matching BIOS disk entry. Disk %d is not be bootable by the BIOS!\n", DiskNumber);
1412#endif
1413 }
1414
1417
1418 DiskEntry->Cylinders = DiskGeometry.Cylinders.QuadPart;
1419 DiskEntry->TracksPerCylinder = DiskGeometry.TracksPerCylinder;
1420 DiskEntry->SectorsPerTrack = DiskGeometry.SectorsPerTrack;
1421 DiskEntry->BytesPerSector = DiskGeometry.BytesPerSector;
1422
1423 DPRINT("Cylinders %I64u\n", DiskEntry->Cylinders);
1424 DPRINT("TracksPerCylinder %I64u\n", DiskEntry->TracksPerCylinder);
1425 DPRINT("SectorsPerTrack %I64u\n", DiskEntry->SectorsPerTrack);
1426 DPRINT("BytesPerSector %I64u\n", DiskEntry->BytesPerSector);
1427
1428 DiskEntry->SectorCount.QuadPart = DiskGeometry.Cylinders.QuadPart *
1429 (ULONGLONG)DiskGeometry.TracksPerCylinder *
1430 (ULONGLONG)DiskGeometry.SectorsPerTrack;
1431
1432// DiskEntry->SectorAlignment = DiskGeometry.SectorsPerTrack;
1433// DiskEntry->CylinderAlignment = DiskGeometry.SectorsPerTrack * DiskGeometry.TracksPerCylinder;
1434 DiskEntry->SectorAlignment = (1024 * 1024) / DiskGeometry.BytesPerSector;
1435 DiskEntry->CylinderAlignment = (1024 * 1024) / DiskGeometry.BytesPerSector;
1436
1437 DPRINT("SectorCount: %I64u\n", DiskEntry->SectorCount);
1438 DPRINT("SectorAlignment: %lu\n", DiskEntry->SectorAlignment);
1439 DPRINT("CylinderAlignment: %lu\n", DiskEntry->CylinderAlignment);
1440
1441 DiskEntry->DiskNumber = DiskNumber;
1442 DiskEntry->Port = ScsiAddress.PortNumber;
1443 DiskEntry->PathId = ScsiAddress.PathId;
1444 DiskEntry->TargetId = ScsiAddress.TargetId;
1445 DiskEntry->Lun = ScsiAddress.Lun;
1446
1447 GetDriverName(DiskEntry);
1448
1449 InsertAscendingList(&DiskListHead, DiskEntry, DISKENTRY, ListEntry, DiskNumber);
1450
1451 ReadLayoutBuffer(FileHandle, DiskEntry);
1452
1453 DPRINT("PartitionCount: %lu\n", DiskEntry->LayoutBuffer->PartitionCount);
1454
1455#ifdef DUMP_PARTITION_TABLE
1456 DumpPartitionTable(DiskEntry);
1457#endif
1458
1459 if (DiskEntry->PartitionStyle == PARTITION_STYLE_MBR)
1460 {
1461 if (DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart != 0 &&
1463 DiskEntry->LayoutBuffer->PartitionEntry[0].Mbr.PartitionType != 0)
1464 {
1465 if ((DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart / DiskEntry->BytesPerSector) % DiskEntry->SectorsPerTrack == 0)
1466 {
1467 DPRINT("Use %lu Sector alignment!\n", DiskEntry->SectorsPerTrack);
1468 }
1469 else if (DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart % (1024 * 1024) == 0)
1470 {
1471 DPRINT1("Use megabyte (%lu Sectors) alignment!\n", (1024 * 1024) / DiskEntry->BytesPerSector);
1472 }
1473 else
1474 {
1475 DPRINT1("No matching alignment found! Partition 1 starts at %I64u\n", DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart);
1476 }
1477 }
1478 else
1479 {
1480 DPRINT1("No valid partition table found! Use megabyte (%lu Sectors) alignment!\n", (1024 * 1024) / DiskEntry->BytesPerSector);
1481 }
1482
1483 /* Calculate the number of usable sectors */
1484 /* Limit the number of usable sectors to 2^32 */
1485 DiskEntry->StartSector.QuadPart = (ULONGLONG)DiskEntry->SectorAlignment;
1486 DiskEntry->EndSector.QuadPart = min(DiskEntry->SectorCount.QuadPart, 0x100000000) - 1;
1487
1488 if (DiskEntry->LayoutBuffer->PartitionCount == 0)
1489 {
1490 DiskEntry->NewDisk = TRUE;
1491 DiskEntry->LayoutBuffer->PartitionCount = 4;
1492
1493 for (i = 0; i < 4; i++)
1495 }
1496 else
1497 {
1498 for (i = 0; i < 4; i++)
1499 {
1500 AddMbrPartitionToDisk(DiskNumber, DiskEntry, i, FALSE);
1501 }
1502
1503 for (i = 4; i < DiskEntry->LayoutBuffer->PartitionCount; i += 4)
1504 {
1505 AddMbrPartitionToDisk(DiskNumber, DiskEntry, i, TRUE);
1506 }
1507 }
1508
1510 }
1511 else if (DiskEntry->PartitionStyle == PARTITION_STYLE_GPT)
1512 {
1513 /* Calculate the number of usable sectors */
1514 DiskEntry->StartSector.QuadPart = AlignDown(DiskEntry->LayoutBuffer->Gpt.StartingUsableOffset.QuadPart / DiskEntry->BytesPerSector,
1515 DiskEntry->SectorAlignment) + (ULONGLONG)DiskEntry->SectorAlignment;
1516 DiskEntry->EndSector.QuadPart = AlignDown(DiskEntry->StartSector.QuadPart + (DiskEntry->LayoutBuffer->Gpt.UsableLength.QuadPart / DiskEntry->BytesPerSector) - 1,
1517 DiskEntry->SectorAlignment);
1518
1519 if (DiskEntry->LayoutBuffer->PartitionCount == 0)
1520 {
1521 DiskEntry->NewDisk = TRUE;
1522 }
1523 else
1524 {
1525 for (i = 0; i < DiskEntry->LayoutBuffer->PartitionCount; i++)
1526 {
1527 AddGptPartitionToDisk(DiskNumber, DiskEntry, i);
1528 }
1529 }
1530
1532 }
1533}
@ Identifier
Definition: asmpp.cpp:103
LONG NTSTATUS
Definition: precomp.h:26
HANDLE ProcessHeap
Definition: servman.c:15
#define DPRINT1
Definition: precomp.h:8
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define ARRAYSIZE(a)
Definition: cat.c:25
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define MultiByteToWideChar
Definition: compat.h:110
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static const WCHAR Signature[]
Definition: parser.c:141
#define L(x)
Definition: resources.c:13
return Iosb
Definition: create.c:4403
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ PARTITION_STYLE_GPT
Definition: imports.h:202
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
@ RemovableMedia
Definition: ntdddisk.h:382
@ FixedMedia
Definition: ntdddisk.h:383
#define PARTITION_GPT
Definition: part_gpt.h:27
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
@ StorageDeviceProperty
Definition: ntddstor.h:512
@ PropertyStandardQuery
Definition: ntddstor.h:505
PVOID pBuffer
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52
wcscat
static VOID GetDriverName(IN PDISKENTRY DiskEntry)
Definition: partlist.c:107
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
#define DPRINT
Definition: sndvol32.h:73
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BOOLEAN Recognized
Definition: diskpart.h:191
ULONG DiskNumber
Definition: partlist.h:162
ULONG Checksum
Definition: partlist.h:164
ULONG Signature
Definition: partlist.h:163
ULARGE_INTEGER EndSector
Definition: diskpart.h:215
ULONG SectorAlignment
Definition: partlist.h:116
ULONG BiosDiskNumber
Definition: diskpart.h:218
ULARGE_INTEGER SectorCount
Definition: partlist.h:115
STORAGE_BUS_TYPE BusType
Definition: diskpart.h:203
ULONG SectorsPerTrack
Definition: partlist.h:112
USHORT TargetId
Definition: diskpart.h:225
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
BOOLEAN NewDisk
Definition: partlist.h:138
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
USHORT PathId
Definition: diskpart.h:224
BOOLEAN BiosFound
Definition: partlist.h:120
ULONGLONG Cylinders
Definition: partlist.h:110
USHORT Lun
Definition: diskpart.h:226
ULARGE_INTEGER StartSector
Definition: diskpart.h:214
USHORT Port
Definition: partlist.h:131
DWORD PartitionStyle
Definition: diskpart.h:232
ULONG TracksPerCylinder
Definition: partlist.h:111
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:149
PWSTR Description
Definition: diskpart.h:201
ULONG CylinderAlignment
Definition: partlist.h:117
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:143
MEDIA_TYPE MediaType
Definition: ntdddisk.h:401
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:400
ULONG TracksPerCylinder
Definition: ntdddisk.h:402
ULONG SectorsPerTrack
Definition: ntdddisk.h:403
ULONG BytesPerSector
Definition: ntdddisk.h:404
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:421
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:408
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:409
BOOLEAN RewritePartition
Definition: ntdddisk.h:415
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:220
unsigned char PartitionType
Definition: partlist.h:207
UCHAR PathId
Definition: scsi_port.h:149
UCHAR TargetId
Definition: scsi_port.h:150
UCHAR PortNumber
Definition: scsi_port.h:148
STORAGE_BUS_TYPE BusType
Definition: ntddstor.h:298
STORAGE_QUERY_TYPE QueryType
Definition: ntddstor.h:553
STORAGE_PROPERTY_ID PropertyId
Definition: ntddstor.h:552
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
ULONGLONG AlignDown(_In_ ULONGLONG Value, _In_ ULONG Alignment)
Definition: partlist.c:189
static VOID AddGptPartitionToDisk(ULONG DiskNumber, PDISKENTRY DiskEntry, ULONG PartitionIndex)
Definition: partlist.c:616
LIST_ENTRY BiosDiskListHead
Definition: partlist.c:72
static VOID AddMbrPartitionToDisk(ULONG DiskNumber, PDISKENTRY DiskEntry, ULONG PartitionIndex, BOOLEAN LogicalPartition)
Definition: partlist.c:506
VOID ReadLayoutBuffer(_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1065
LIST_ENTRY DiskListHead
Definition: partlist.c:71
VOID ScanForUnpartitionedMbrDiskSpace(PDISKENTRY DiskEntry)
Definition: partlist.c:660
VOID ScanForUnpartitionedGptDiskSpace(PDISKENTRY DiskEntry)
Definition: partlist.c:921
#define MBR_MAGIC
Definition: partlist.c:39
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
char * PSTR
Definition: typedefs.h:51
int32_t INT
Definition: typedefs.h:58
uint64_t ULONGLONG
Definition: typedefs.h:67
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
struct _STORAGE_DESCRIPTOR_HEADER * PSTORAGE_DESCRIPTOR_HEADER
struct _STORAGE_DEVICE_DESCRIPTOR * PSTORAGE_DEVICE_DESCRIPTOR

◆ AddGptPartitionToDisk()

static VOID AddGptPartitionToDisk ( ULONG  DiskNumber,
PDISKENTRY  DiskEntry,
ULONG  PartitionIndex 
)
static

Definition at line 616 of file partlist.c.

620{
622 PPARTENTRY PartEntry;
623
624 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartitionIndex];
625 if (IsEqualGUID(&PartitionInfo->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
626 return;
627
628 PartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
630 sizeof(PARTENTRY));
631 if (PartEntry == NULL)
632 {
633 /* TODO: Error message */
634 return;
635 }
636
637 PartEntry->DiskEntry = DiskEntry;
638
639 PartEntry->StartSector.QuadPart = (ULONGLONG)PartitionInfo->StartingOffset.QuadPart / DiskEntry->BytesPerSector;
640 PartEntry->SectorCount.QuadPart = (ULONGLONG)PartitionInfo->PartitionLength.QuadPart / DiskEntry->BytesPerSector;
641
642 CopyMemory(&PartEntry->Gpt.PartitionType, &PartitionInfo->Gpt.PartitionType, sizeof(GUID));
643 CopyMemory(&PartEntry->Gpt.PartitionId, &PartitionInfo->Gpt.PartitionId, sizeof(GUID));
644 PartEntry->Gpt.Attributes = PartitionInfo->Gpt.Attributes;
645
646 PartEntry->LogicalPartition = FALSE;
647 PartEntry->IsPartitioned = TRUE;
648 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
649 PartEntry->PartitionIndex = PartitionIndex;
650
651 /* TODO: Determine the format state */
652 PartEntry->FormatState = Unformatted;
653
655 &PartEntry->ListEntry);
656}
#define InsertTailList(ListHead, Entry)
@ Unformatted
Definition: partlist.h:34
#define CopyMemory
Definition: minwinbase.h:29
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
DWORD64 Attributes
Definition: diskpart.h:136
BOOLEAN IsPartitioned
Definition: partlist.h:82
ULARGE_INTEGER SectorCount
Definition: partlist.h:70
struct _DISKENTRY * DiskEntry
Definition: partlist.h:66
BOOLEAN LogicalPartition
Definition: partlist.h:79
FORMATSTATE FormatState
Definition: diskpart.h:161
GPT_PARTITION_DATA Gpt
Definition: diskpart.h:151
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULONG PartitionNumber
Definition: partlist.h:75
ULARGE_INTEGER StartSector
Definition: partlist.h:69
ULONG PartitionIndex
Definition: partlist.h:76
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105

Referenced by AddDiskToList().

◆ AddMbrPartitionToDisk()

static VOID AddMbrPartitionToDisk ( ULONG  DiskNumber,
PDISKENTRY  DiskEntry,
ULONG  PartitionIndex,
BOOLEAN  LogicalPartition 
)
static

Definition at line 506 of file partlist.c.

511{
513 PPARTENTRY PartEntry;
514
515 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartitionIndex];
516 if (PartitionInfo->Mbr.PartitionType == 0 ||
517 (LogicalPartition == TRUE && IsContainerPartition(PartitionInfo->Mbr.PartitionType)))
518 return;
519
520 PartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
522 sizeof(PARTENTRY));
523 if (PartEntry == NULL)
524 {
525 /* TODO: Error message */
526 return;
527 }
528
529 PartEntry->DiskEntry = DiskEntry;
530
531 PartEntry->StartSector.QuadPart = (ULONGLONG)PartitionInfo->StartingOffset.QuadPart / DiskEntry->BytesPerSector;
532 PartEntry->SectorCount.QuadPart = (ULONGLONG)PartitionInfo->PartitionLength.QuadPart / DiskEntry->BytesPerSector;
533
534 PartEntry->Mbr.BootIndicator = PartitionInfo->Mbr.BootIndicator;
535 PartEntry->Mbr.PartitionType = PartitionInfo->Mbr.PartitionType;
536
538 PartEntry->IsPartitioned = TRUE;
539 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
540 PartEntry->PartitionIndex = PartitionIndex;
541
542 if (IsContainerPartition(PartEntry->Mbr.PartitionType))
543 {
544 PartEntry->FormatState = Unformatted;
545
546 if (LogicalPartition == FALSE && DiskEntry->ExtendedPartition == NULL)
547 DiskEntry->ExtendedPartition = PartEntry;
548 }
549 else if ((PartEntry->Mbr.PartitionType == PARTITION_FAT_12) ||
550 (PartEntry->Mbr.PartitionType == PARTITION_FAT_16) ||
551 (PartEntry->Mbr.PartitionType == PARTITION_HUGE) ||
552 (PartEntry->Mbr.PartitionType == PARTITION_XINT13) ||
553 (PartEntry->Mbr.PartitionType == PARTITION_FAT32) ||
555 {
556#if 0
557 if (CheckFatFormat())
558 {
559 PartEntry->FormatState = Preformatted;
560 }
561 else
562 {
563 PartEntry->FormatState = Unformatted;
564 }
565#endif
566 PartEntry->FormatState = Preformatted;
567 }
568 else if (PartEntry->Mbr.PartitionType == PARTITION_LINUX)
569 {
570#if 0
571 if (CheckExt2Format())
572 {
573 PartEntry->FormatState = Preformatted;
574 }
575 else
576 {
577 PartEntry->FormatState = Unformatted;
578 }
579#endif
580 PartEntry->FormatState = Preformatted;
581 }
582 else if (PartEntry->Mbr.PartitionType == PARTITION_IFS)
583 {
584#if 0
585 if (CheckNtfsFormat())
586 {
587 PartEntry->FormatState = Preformatted;
588 }
589 else if (CheckHpfsFormat())
590 {
591 PartEntry->FormatState = Preformatted;
592 }
593 else
594 {
595 PartEntry->FormatState = Unformatted;
596 }
597#endif
598 PartEntry->FormatState = Preformatted;
599 }
600 else
601 {
602 PartEntry->FormatState = UnknownFormat;
603 }
604
607 &PartEntry->ListEntry);
608 else
610 &PartEntry->ListEntry);
611}
@ Preformatted
Definition: diskpart.h:105
@ LogicalPartition
Definition: disksup.c:34
@ UnknownFormat
Definition: partlist.h:36
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:321
#define PARTITION_IFS
Definition: part_mbr.h:57
#define PARTITION_XINT13
Definition: part_mbr.h:61
#define PARTITION_FAT32
Definition: part_mbr.h:59
#define PARTITION_FAT_12
Definition: part_mbr.h:51
#define PARTITION_HUGE
Definition: part_mbr.h:56
#define PARTITION_FAT_16
Definition: part_mbr.h:54
#define PARTITION_FAT32_XINT13
Definition: part_mbr.h:60
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
BOOLEAN BootIndicator
Definition: diskpart.h:128
MBR_PARTITION_DATA Mbr
Definition: diskpart.h:150
#define PARTITION_LINUX
Definition: partlist.c:35

Referenced by AddDiskToList().

◆ AddVolumeToList()

static VOID AddVolumeToList ( ULONG  ulVolumeNumber,
PWSTR  pszVolumeName 
)
static

Definition at line 2023 of file partlist.c.

2026{
2027 PVOLENTRY VolumeEntry;
2029
2030 DWORD dwError, dwLength;
2031 WCHAR szPathNames[MAX_PATH + 1];
2032 WCHAR szVolumeName[MAX_PATH + 1];
2033 WCHAR szFilesystem[MAX_PATH + 1];
2034
2035 DWORD CharCount = 0;
2036 size_t Index = 0;
2037
2042
2043 DPRINT("AddVolumeToList(%S)\n", pszVolumeName);
2044
2045 VolumeEntry = RtlAllocateHeap(RtlGetProcessHeap(),
2047 sizeof(VOLENTRY));
2048 if (VolumeEntry == NULL)
2049 return;
2050
2051 VolumeEntry->VolumeNumber = ulVolumeNumber;
2052 wcscpy(VolumeEntry->VolumeName, pszVolumeName);
2053
2054 Index = wcslen(pszVolumeName) - 1;
2055
2056 pszVolumeName[Index] = L'\0';
2057
2058 CharCount = QueryDosDeviceW(&pszVolumeName[4], VolumeEntry->DeviceName, ARRAYSIZE(VolumeEntry->DeviceName));
2059
2060 pszVolumeName[Index] = L'\\';
2061
2062 if (CharCount == 0)
2063 {
2064 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2065 return;
2066 }
2067
2068 DPRINT("DeviceName: %S\n", VolumeEntry->DeviceName);
2069
2070 RtlInitUnicodeString(&Name, VolumeEntry->DeviceName);
2071
2073 &Name,
2074 0,
2075 NULL,
2076 NULL);
2077
2081 &Iosb,
2082 0,
2084 if (NT_SUCCESS(Status))
2085 {
2086 GetVolumeType(VolumeHandle, VolumeEntry);
2087 GetVolumeExtents(VolumeHandle, VolumeEntry);
2089 }
2090
2091 if (GetVolumeInformationW(pszVolumeName,
2092 szVolumeName,
2093 MAX_PATH + 1,
2094 &VolumeEntry->SerialNumber,
2095 NULL,
2096 NULL,
2097 szFilesystem,
2098 MAX_PATH + 1))
2099 {
2100 VolumeEntry->pszLabel = RtlAllocateHeap(RtlGetProcessHeap(),
2101 0,
2102 (wcslen(szVolumeName) + 1) * sizeof(WCHAR));
2103 if (VolumeEntry->pszLabel)
2104 wcscpy(VolumeEntry->pszLabel, szVolumeName);
2105
2106 VolumeEntry->pszFilesystem = RtlAllocateHeap(RtlGetProcessHeap(),
2107 0,
2108 (wcslen(szFilesystem) + 1) * sizeof(WCHAR));
2109 if (VolumeEntry->pszFilesystem)
2110 wcscpy(VolumeEntry->pszFilesystem, szFilesystem);
2111 VolumeEntry->VolumeStatus = VOLUME_STATUS_HEALTHY;
2112 }
2113 else
2114 {
2115 dwError = GetLastError();
2116 if (dwError == ERROR_UNRECOGNIZED_VOLUME)
2117 {
2118 VolumeEntry->pszFilesystem = RtlAllocateHeap(RtlGetProcessHeap(),
2119 0,
2120 (3 + 1) * sizeof(WCHAR));
2121 if (VolumeEntry->pszFilesystem)
2122 wcscpy(VolumeEntry->pszFilesystem, L"RAW");
2123 VolumeEntry->SerialNumber = 0;
2124 VolumeEntry->SectorsPerAllocationUnit = 1;
2125 VolumeEntry->BytesPerSector = 512;
2126 VolumeEntry->VolumeType = VOLUME_TYPE_PARTITION;
2127 VolumeEntry->VolumeStatus = VOLUME_STATUS_HEALTHY;
2128 }
2129 else if (dwError == ERROR_NOT_READY)
2130 {
2131 VolumeEntry->VolumeStatus = VOLUME_STATUS_NO_MEDIA;
2132 VolumeEntry->Size.QuadPart = 0;
2133 }
2134 }
2135
2136 if (GetVolumePathNamesForVolumeNameW(pszVolumeName,
2137 szPathNames,
2138 ARRAYSIZE(szPathNames),
2139 &dwLength))
2140 {
2141 INT nPathLength;
2142 PWSTR pszPath = szPathNames;
2143 while (*pszPath != UNICODE_NULL)
2144 {
2145 DPRINT("PathName: %S\n", pszPath);
2146 nPathLength = wcslen(pszPath);
2147 if ((nPathLength == 3) && (iswalpha(pszPath[0])) &&
2148 (pszPath[1] == L':') && (pszPath[2] == L'\\'))
2149 VolumeEntry->DriveLetter = pszPath[0];
2150
2151 pszPath += (nPathLength + 1);
2152 }
2153 }
2154
2155 IsVolumeSystem(VolumeEntry);
2156 IsVolumeBoot(VolumeEntry);
2157
2159 &VolumeEntry->ListEntry);
2160}
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
LPWSTR Name
Definition: desk.c:124
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:112
@ VOLUME_STATUS_HEALTHY
Definition: diskpart.h:119
@ VOLUME_STATUS_NO_MEDIA
Definition: diskpart.h:121
#define MAX_PATH
Definition: compat.h:34
static DWORD DWORD * dwLength
Definition: fusion.c:86
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
Definition: dosdev.c:542
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
BOOL WINAPI GetVolumePathNamesForVolumeNameW(IN LPCWSTR lpszVolumeName, IN LPWSTR lpszVolumePathNames, IN DWORD cchBufferLength, OUT PDWORD lpcchReturnLength)
Definition: volume.c:1163
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _Out_ PHANDLE VolumeHandle
Definition: fltkernel.h:2283
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3434
#define UNICODE_NULL
#define iswalpha(_c)
Definition: ctype.h:664
wcscpy
ULARGE_INTEGER Size
Definition: diskpart.h:261
VOLUME_TYPE VolumeType
Definition: diskpart.h:260
ULONG VolumeNumber
Definition: diskpart.h:251
ULONG SectorsPerAllocationUnit
Definition: diskpart.h:265
PWSTR pszFilesystem
Definition: diskpart.h:259
ULONG BytesPerSector
Definition: diskpart.h:266
VOLUME_STATUS VolumeStatus
Definition: diskpart.h:270
DWORD SerialNumber
Definition: diskpart.h:254
WCHAR VolumeName[MAX_PATH]
Definition: diskpart.h:252
LIST_ENTRY ListEntry
Entry in VolumesList or PendingUnmountVolumesList.
Definition: partlist.h:45
PWSTR pszLabel
Definition: diskpart.h:258
WCHAR DeviceName[MAX_PATH]
Definition: diskpart.h:253
WCHAR DriveLetter
Definition: diskpart.h:256
LIST_ENTRY VolumeListHead
Definition: partlist.c:73
static VOID GetVolumeType(_In_ HANDLE VolumeHandle, _In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1741
static VOID IsVolumeBoot(_In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1986
static VOID IsVolumeSystem(_In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1932
static VOID GetVolumeExtents(_In_ HANDLE VolumeHandle, _In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1675
_In_ WDFCOLLECTION _In_ ULONG Index
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_UNRECOGNIZED_VOLUME
Definition: winerror.h:908
#define ERROR_NOT_READY
Definition: winerror.h:246

Referenced by CreateVolumeList().

◆ AlignDown()

ULONGLONG AlignDown ( _In_ ULONGLONG  Value,
_In_ ULONG  Alignment 
)

Definition at line 189 of file partlist.c.

192{
193 ULONGLONG Temp;
194
195 Temp = Value / Alignment;
196
197 return Temp * Alignment;
198}
union Alignment_ Alignment
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ CreatePartitionList()

NTSTATUS CreatePartitionList ( VOID  )

Definition at line 1537 of file partlist.c.

1538{
1542 ULONG ReturnSize;
1544 ULONG DiskNumber;
1548
1549 CurrentDisk = NULL;
1551
1552// BootDisk = NULL;
1553// BootPartition = NULL;
1554
1555// TempDisk = NULL;
1556// TempPartition = NULL;
1557// FormatState = Start;
1558
1561
1563
1565 &Sdi,
1567 &ReturnSize);
1568 if (!NT_SUCCESS(Status))
1569 {
1570 return Status;
1571 }
1572
1573 for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++)
1574 {
1576 L"\\Device\\Harddisk%d\\Partition0",
1577 DiskNumber);
1578
1580 Buffer);
1581
1583 &Name,
1584 0,
1585 NULL,
1586 NULL);
1587
1591 &Iosb,
1594 if (NT_SUCCESS(Status))
1595 {
1596 AddDiskToList(FileHandle, DiskNumber);
1597
1599 }
1600 }
1601
1602// UpdateDiskSignatures(List);
1603
1604// AssignDriveLetters(List);
1605
1606 return STATUS_SUCCESS;
1607}
PDISKENTRY CurrentDisk
Definition: partlist.c:75
#define FILE_SHARE_READ
Definition: compat.h:136
@ SystemDeviceInformation
Definition: ntddk_ex.h:18
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
static VOID AddDiskToList(IN HANDLE FileHandle, IN ULONG DiskNumber, IN PPARTLIST List)
Definition: partlist.c:1500
static VOID EnumerateBiosDiskEntries(IN PPARTLIST PartList)
Definition: partlist.c:329
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
PPARTENTRY CurrentPartition
Definition: partlist.c:76

◆ CreateVolumeList()

NTSTATUS CreateVolumeList ( VOID  )

Definition at line 2227 of file partlist.c.

2228{
2229 HANDLE hVolume = INVALID_HANDLE_VALUE;
2230 WCHAR szVolumeName[MAX_PATH];
2231 ULONG ulVolumeNumber = 0;
2232 BOOL Success;
2233
2235
2237
2238 hVolume = FindFirstVolumeW(szVolumeName, ARRAYSIZE(szVolumeName));
2239 if (hVolume == INVALID_HANDLE_VALUE)
2240 {
2241
2242 return STATUS_UNSUCCESSFUL;
2243 }
2244
2245 AddVolumeToList(ulVolumeNumber++, szVolumeName);
2246
2247 for (;;)
2248 {
2249 Success = FindNextVolumeW(hVolume, szVolumeName, ARRAYSIZE(szVolumeName));
2250 if (!Success)
2251 {
2252 break;
2253 }
2254
2255 AddVolumeToList(ulVolumeNumber++, szVolumeName);
2256 }
2257
2258 FindVolumeClose(hVolume);
2259
2261
2262 return STATUS_SUCCESS;
2263}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindNextVolumeW(IN HANDLE handle, IN LPWSTR volume, IN DWORD len)
Definition: volume.c:1018
HANDLE WINAPI FindFirstVolumeW(IN LPWSTR volume, IN DWORD len)
Definition: volume.c:660
BOOL WINAPI FindVolumeClose(IN HANDLE hFindVolume)
Definition: volume.c:741
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
static VOID AddVolumeToList(ULONG ulVolumeNumber, PWSTR pszVolumeName)
Definition: partlist.c:2023
static VOID SortVolumeList(VOID)
Definition: partlist.c:2178
PVOLENTRY CurrentVolume
Definition: partlist.c:77
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by rescan_main(), and wmain().

◆ DestroyPartitionList()

VOID DestroyPartitionList ( VOID  )

Definition at line 1611 of file partlist.c.

1612{
1613 PDISKENTRY DiskEntry;
1614 PBIOSDISKENTRY BiosDiskEntry;
1615 PPARTENTRY PartEntry;
1617
1618 CurrentDisk = NULL;
1620
1621 /* Release disk and partition info */
1622 while (!IsListEmpty(&DiskListHead))
1623 {
1625 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1626
1627 /* Release driver name */
1628 RtlFreeUnicodeString(&DiskEntry->DriverName);
1629
1630 /* Release primary partition list */
1631 while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1632 {
1634 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1635
1636 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1637 }
1638
1639 /* Release logical partition list */
1640 while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1641 {
1643 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1644
1645 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1646 }
1647
1648 /* Release layout buffer */
1649 if (DiskEntry->LayoutBuffer != NULL)
1650 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->LayoutBuffer);
1651
1652 if (DiskEntry->Description != NULL)
1653 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->Description);
1654
1655 if (DiskEntry->Location != NULL)
1656 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->Location);
1657
1658 /* Release disk entry */
1659 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry);
1660 }
1661
1662 /* Release the bios disk info */
1663 while (!IsListEmpty(&BiosDiskListHead))
1664 {
1666 BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1667
1668 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
1669 }
1670}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Entry
Definition: section.c:5216
UNICODE_STRING DriverName
Definition: partlist.h:141
PWSTR Location
Definition: diskpart.h:202

◆ DestroyVolumeList()

VOID DestroyVolumeList ( VOID  )

Definition at line 2267 of file partlist.c.

2268{
2270 PVOLENTRY VolumeEntry;
2271
2273
2274 /* Release disk and partition info */
2275 while (!IsListEmpty(&VolumeListHead))
2276 {
2278 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2279
2280 if (VolumeEntry->pszLabel)
2281 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2282
2283 if (VolumeEntry->pszFilesystem)
2284 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2285
2286 if (VolumeEntry->pExtents)
2287 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
2288
2289 /* Release disk entry */
2290 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2291 }
2292}
PVOLUME_DISK_EXTENTS pExtents
Definition: diskpart.h:272

Referenced by rescan_main(), and wmain().

◆ DiskConfigurationDataQueryRoutine()

static NTSTATUS NTAPI DiskConfigurationDataQueryRoutine ( PWSTR  ValueName,
ULONG  ValueType,
PVOID  ValueData,
ULONG  ValueLength,
PVOID  Context,
PVOID  EntryContext 
)
static

Definition at line 267 of file partlist.c.

274{
275 PBIOSDISKENTRY BiosDiskEntry = (PBIOSDISKENTRY)Context;
276 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
278 ULONG i;
279
282 return STATUS_UNSUCCESSFUL;
283
284 FullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)ValueData;
285
286 /* Hm. Version and Revision are not set on Microsoft Windows XP... */
287#if 0
288 if (FullResourceDescriptor->PartialResourceList.Version != 1 ||
289 FullResourceDescriptor->PartialResourceList.Revision != 1)
290 return STATUS_UNSUCCESSFUL;
291#endif
292
293 for (i = 0; i < FullResourceDescriptor->PartialResourceList.Count; i++)
294 {
297 continue;
298
299 DiskGeometry = (PCM_DISK_GEOMETRY_DEVICE_DATA)&FullResourceDescriptor->PartialResourceList.PartialDescriptors[i + 1];
300 BiosDiskEntry->DiskGeometry = *DiskGeometry;
301
302 return STATUS_SUCCESS;
303 }
304
305 return STATUS_UNSUCCESSFUL;
306}
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
struct _BIOSDISKENTRY * PBIOSDISKENTRY
#define REG_FULL_RESOURCE_DESCRIPTOR
Definition: nt_native.h:1506
struct _CM_FULL_RESOURCE_DESCRIPTOR * PCM_FULL_RESOURCE_DESCRIPTOR
#define CmResourceTypeDeviceSpecific
Definition: restypes.h:108
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:166
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: restypes.h:145
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494::@503 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494 u
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
struct _CM_DISK_GEOMETRY_DEVICE_DATA * PCM_DISK_GEOMETRY_DEVICE_DATA

◆ DiskIdentifierQueryRoutine()

static NTSTATUS NTAPI DiskIdentifierQueryRoutine ( PWSTR  ValueName,
ULONG  ValueType,
PVOID  ValueData,
ULONG  ValueLength,
PVOID  Context,
PVOID  EntryContext 
)
static

Definition at line 237 of file partlist.c.

244{
245 PBIOSDISKENTRY BiosDiskEntry = (PBIOSDISKENTRY)Context;
246 UNICODE_STRING NameU;
247
248 if (ValueType == REG_SZ &&
249 ValueLength == 20 * sizeof(WCHAR))
250 {
251 NameU.Buffer = (PWCHAR)ValueData;
252 NameU.Length = NameU.MaximumLength = 8 * sizeof(WCHAR);
253 RtlUnicodeStringToInteger(&NameU, 16, &BiosDiskEntry->Checksum);
254
255 NameU.Buffer = (PWCHAR)ValueData + 9;
256 RtlUnicodeStringToInteger(&NameU, 16, &BiosDiskEntry->Signature);
257
258 return STATUS_SUCCESS;
259 }
260
261 return STATUS_UNSUCCESSFUL;
262}
#define REG_SZ
Definition: layer.c:22
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWCHAR
Definition: typedefs.h:56

◆ DismountVolume()

NTSTATUS DismountVolume ( _In_ PPARTENTRY  PartEntry)

Definition at line 3056 of file partlist.c.

3058{
3060 NTSTATUS LockStatus;
3064 HANDLE PartitionHandle;
3066
3067 /* Check whether the partition is valid and was mounted by the system */
3068 if (PartEntry->DiskEntry->PartitionStyle == PARTITION_STYLE_MBR)
3069 {
3070 if (!PartEntry->IsPartitioned ||
3071 IsContainerPartition(PartEntry->Mbr.PartitionType) ||
3072 !IsRecognizedPartition(PartEntry->Mbr.PartitionType) ||
3073 PartEntry->FormatState == UnknownFormat ||
3074 // NOTE: If FormatState == Unformatted but *FileSystem != 0 this means
3075 // it has been usually mounted with RawFS and thus needs to be dismounted.
3076/* !*PartEntry->FileSystem || */
3077 PartEntry->PartitionNumber == 0)
3078 {
3079 /* The partition is not mounted, so just return success */
3080 return STATUS_SUCCESS;
3081 }
3082
3083 ASSERT(PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED);
3084 }
3085 else if (PartEntry->DiskEntry->PartitionStyle == PARTITION_STYLE_GPT)
3086 {
3087 if (!PartEntry->IsPartitioned ||
3088 IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID) ||
3089 (PartEntry->FormatState == UnknownFormat))
3090 {
3091 /* The partition is not mounted, so just return success */
3092 return STATUS_SUCCESS;
3093 }
3094 }
3095
3096 /* Open the volume */
3098 L"\\Device\\Harddisk%lu\\Partition%lu",
3099 PartEntry->DiskEntry->DiskNumber,
3100 PartEntry->PartitionNumber);
3102
3104 &Name,
3106 NULL,
3107 NULL);
3108
3109 Status = NtOpenFile(&PartitionHandle,
3115 if (!NT_SUCCESS(Status))
3116 {
3117 DPRINT1("ERROR: Cannot open volume %wZ for dismounting! (Status 0x%lx)\n", &Name, Status);
3118 return Status;
3119 }
3120
3121 /* Lock the volume */
3122 LockStatus = NtFsControlFile(PartitionHandle,
3123 NULL,
3124 NULL,
3125 NULL,
3128 NULL,
3129 0,
3130 NULL,
3131 0);
3132 if (!NT_SUCCESS(LockStatus))
3133 {
3134 DPRINT1("WARNING: Failed to lock volume! Operations may fail! (Status 0x%lx)\n", LockStatus);
3135 }
3136
3137 /* Dismount the volume */
3138 Status = NtFsControlFile(PartitionHandle,
3139 NULL,
3140 NULL,
3141 NULL,
3144 NULL,
3145 0,
3146 NULL,
3147 0);
3148 if (!NT_SUCCESS(Status))
3149 {
3150 DPRINT1("Failed to unmount volume (Status 0x%lx)\n", Status);
3151 }
3152
3153 /* Unlock the volume */
3154 LockStatus = NtFsControlFile(PartitionHandle,
3155 NULL,
3156 NULL,
3157 NULL,
3160 NULL,
3161 0,
3162 NULL,
3163 0);
3164 if (!NT_SUCCESS(LockStatus))
3165 {
3166 DPRINT1("Failed to unlock volume (Status 0x%lx)\n", LockStatus);
3167 }
3168
3169 /* Close the volume */
3170 NtClose(PartitionHandle);
3171
3172 return Status;
3173}
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
#define GENERIC_READ
Definition: compat.h:135
#define ASSERT(a)
Definition: mode.c:44
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342
#define PARTITION_ENTRY_UNUSED
Definition: part_mbr.h:50
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228

◆ EnumerateBiosDiskEntries()

static VOID EnumerateBiosDiskEntries ( VOID  )
static

Definition at line 361 of file partlist.c.

362{
364 WCHAR Name[120];
365 ULONG AdapterCount;
366 ULONG DiskCount;
368 PCM_INT13_DRIVE_PARAMETER Int13Drives;
369 PBIOSDISKENTRY BiosDiskEntry;
370
371 memset(QueryTable, 0, sizeof(QueryTable));
372
373 QueryTable[1].Name = L"Configuration Data";
375 Int13Drives = NULL;
377 L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System",
378 &QueryTable[1],
379 (PVOID)&Int13Drives,
380 NULL);
381 if (!NT_SUCCESS(Status))
382 {
383 DPRINT1("Unable to query the 'Configuration Data' key in '\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System', status=%lx\n", Status);
384 return;
385 }
386
387 AdapterCount = 0;
388 while (1)
389 {
391 L"%s\\%lu", ROOT_NAME, AdapterCount);
393 Name,
394 &QueryTable[2],
395 NULL,
396 NULL);
397 if (!NT_SUCCESS(Status))
398 {
399 break;
400 }
401
403 L"%s\\%lu\\DiskController", ROOT_NAME, AdapterCount);
405 Name,
406 &QueryTable[2],
407 NULL,
408 NULL);
409 if (NT_SUCCESS(Status))
410 {
411 while (1)
412 {
414 L"%s\\%lu\\DiskController\\0", ROOT_NAME, AdapterCount);
416 Name,
417 &QueryTable[2],
418 NULL,
419 NULL);
420 if (!NT_SUCCESS(Status))
421 {
422 RtlFreeHeap(RtlGetProcessHeap(), 0, Int13Drives);
423 return;
424 }
425
427 L"%s\\%lu\\DiskController\\0\\DiskPeripheral", ROOT_NAME, AdapterCount);
429 Name,
430 &QueryTable[2],
431 NULL,
432 NULL);
433 if (NT_SUCCESS(Status))
434 {
435 QueryTable[0].Name = L"Identifier";
437 QueryTable[1].Name = L"Configuration Data";
439
440 DiskCount = 0;
441 while (1)
442 {
443 BiosDiskEntry = (BIOSDISKENTRY*)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BIOSDISKENTRY));
444 if (BiosDiskEntry == NULL)
445 {
446 break;
447 }
448
450 L"%s\\%lu\\DiskController\\0\\DiskPeripheral\\%lu", ROOT_NAME, AdapterCount, DiskCount);
452 Name,
454 (PVOID)BiosDiskEntry,
455 NULL);
456 if (!NT_SUCCESS(Status))
457 {
458 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
459 break;
460 }
461
462 BiosDiskEntry->DiskNumber = DiskCount;
463 BiosDiskEntry->Recognized = FALSE;
464
465 if (DiskCount < Int13Drives[0].NumberDrives)
466 {
467 BiosDiskEntry->Int13DiskData = Int13Drives[DiskCount];
468 }
469 else
470 {
471 DPRINT1("Didn't find int13 drive datas for disk %u\n", DiskCount);
472 }
473
474 InsertTailList(&BiosDiskListHead, &BiosDiskEntry->ListEntry);
475
476 DPRINT("DiskNumber: %lu\n", BiosDiskEntry->DiskNumber);
477 DPRINT("Signature: %08lx\n", BiosDiskEntry->Signature);
478 DPRINT("Checksum: %08lx\n", BiosDiskEntry->Checksum);
479 DPRINT("BytesPerSector: %lu\n", BiosDiskEntry->DiskGeometry.BytesPerSector);
480 DPRINT("NumberOfCylinders: %lu\n", BiosDiskEntry->DiskGeometry.NumberOfCylinders);
481 DPRINT("NumberOfHeads: %lu\n", BiosDiskEntry->DiskGeometry.NumberOfHeads);
482 DPRINT("DriveSelect: %02x\n", BiosDiskEntry->Int13DiskData.DriveSelect);
483 DPRINT("MaxCylinders: %lu\n", BiosDiskEntry->Int13DiskData.MaxCylinders);
484 DPRINT("SectorsPerTrack: %d\n", BiosDiskEntry->Int13DiskData.SectorsPerTrack);
485 DPRINT("MaxHeads: %d\n", BiosDiskEntry->Int13DiskData.MaxHeads);
486 DPRINT("NumberDrives: %d\n", BiosDiskEntry->Int13DiskData.NumberDrives);
487
488 DiskCount++;
489 }
490 }
491
492 RtlFreeHeap(RtlGetProcessHeap(), 0, Int13Drives);
493 return;
494 }
495 }
496
497 AdapterCount++;
498 }
499
500 RtlFreeHeap(RtlGetProcessHeap(), 0, Int13Drives);
501}
struct _BIOSDISKENTRY BIOSDISKENTRY
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4231
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define memset(x, y, z)
Definition: compat.h:39
static NTSTATUS NTAPI DiskConfigurationDataQueryRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: partlist.c:239
#define ROOT_NAME
static NTSTATUS NTAPI SystemConfigurationDataQueryRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: partlist.c:282
static NTSTATUS NTAPI DiskIdentifierQueryRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: partlist.c:209
LIST_ENTRY ListEntry
Definition: partlist.h:159
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:167
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)

◆ GetDiskForVolume()

static PDISKENTRY GetDiskForVolume ( _In_ PVOLENTRY  VolumeEntry)
static

Definition at line 1834 of file partlist.c.

1836{
1838 PDISKENTRY DiskEntry;
1839 INT i;
1840
1841 DPRINT("GetDiskFromVolume(%p)\n", VolumeEntry);
1842
1843 DPRINT("Extents: %p\n", VolumeEntry->pExtents);
1844 if (VolumeEntry->pExtents == NULL)
1845 return NULL;
1846
1847 DPRINT("Extents: %lu\n", VolumeEntry->pExtents->NumberOfDiskExtents);
1848
1850 while (Entry != &DiskListHead)
1851 {
1852 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1853
1854 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
1855 {
1856 DPRINT("DiskNumber: %lu -- %lu\n", VolumeEntry->pExtents->Extents[i].DiskNumber, DiskEntry->DiskNumber);
1857 if (VolumeEntry->pExtents->Extents[i].DiskNumber == DiskEntry->DiskNumber)
1858 return DiskEntry;
1859 }
1860
1861 Entry = Entry->Flink;
1862 }
1863
1864 return NULL;
1865}

Referenced by IsVolumeBoot().

◆ GetDriverName()

static VOID GetDriverName ( PDISKENTRY  DiskEntry)
static

Definition at line 202 of file partlist.c.

204{
206 WCHAR KeyName[32];
208
210 NULL);
211
213 L"\\Scsi\\Scsi Port %lu",
214 DiskEntry->Port);
215
217 sizeof(QueryTable));
218
219 QueryTable[0].Name = L"Driver";
221 QueryTable[0].EntryContext = &DiskEntry->DriverName;
222
224 KeyName,
226 NULL,
227 NULL);
228 if (!NT_SUCCESS(Status))
229 {
230 DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
231 }
232}
#define RTL_REGISTRY_DEVICEMAP
Definition: nt_native.h:165
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705

◆ GetLogicalPartitionCount()

static ULONG GetLogicalPartitionCount ( _In_ PDISKENTRY  DiskEntry)
static

Definition at line 2657 of file partlist.c.

2659{
2660 PLIST_ENTRY ListEntry;
2661 PPARTENTRY PartEntry;
2662 ULONG Count = 0;
2663
2664 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
2665 ListEntry != &DiskEntry->LogicalPartListHead;
2666 ListEntry = ListEntry->Flink)
2667 {
2668 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2669 if (PartEntry->IsPartitioned)
2670 Count++;
2671 }
2672
2673 return Count;
2674}
int Count
Definition: noreturn.cpp:7

◆ GetNextUnpartitionedEntry()

PPARTENTRY GetNextUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 3027 of file partlist.c.

3029{
3030 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
3031 PPARTENTRY NextPartEntry;
3032 PLIST_ENTRY ListHead;
3033
3034 if (PartEntry->LogicalPartition)
3035 ListHead = &DiskEntry->LogicalPartListHead;
3036 else
3037 ListHead = &DiskEntry->PrimaryPartListHead;
3038
3039 if (PartEntry->ListEntry.Flink != ListHead)
3040 {
3041 NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink,
3042 PARTENTRY,
3043 ListEntry);
3044 if (!NextPartEntry->IsPartitioned)
3045 {
3047 return NextPartEntry;
3048 }
3049 }
3050
3051 return NULL;
3052}

Referenced by DeleteGptPartition(), and DeleteMbrPartition().

◆ GetPartitionForVolume()

static PPARTENTRY GetPartitionForVolume ( _In_ PVOLENTRY  VolumeEntry)
static

Definition at line 1870 of file partlist.c.

1872{
1873 PLIST_ENTRY Entry1, Entry2;
1874 PDISKENTRY DiskEntry;
1875 PPARTENTRY PartEntry;
1876 INT i;
1877
1878 DPRINT("GetPartitionFromVolume(%p)\n", VolumeEntry);
1879
1880 DPRINT("Extents: %p\n", VolumeEntry->pExtents);
1881 if (VolumeEntry->pExtents == NULL)
1882 return NULL;
1883
1884 DPRINT("Extents: %lu\n", VolumeEntry->pExtents->NumberOfDiskExtents);
1885
1886 Entry1 = DiskListHead.Flink;
1887 while (Entry1 != &DiskListHead)
1888 {
1889 DiskEntry = CONTAINING_RECORD(Entry1, DISKENTRY, ListEntry);
1890
1891 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
1892 {
1893 DPRINT("DiskNumber: %lu -- %lu\n", VolumeEntry->pExtents->Extents[i].DiskNumber, DiskEntry->DiskNumber);
1894 if (VolumeEntry->pExtents->Extents[i].DiskNumber == DiskEntry->DiskNumber)
1895 {
1896
1897 Entry2 = DiskEntry->PrimaryPartListHead.Flink;
1898 while (Entry2 != &DiskEntry->PrimaryPartListHead)
1899 {
1900 PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
1901
1902 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
1903 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
1904 return PartEntry;
1905
1906 Entry2 = Entry2->Flink;
1907 }
1908
1909 Entry2 = DiskEntry->LogicalPartListHead.Flink;
1910 while (Entry2 != &DiskEntry->LogicalPartListHead)
1911 {
1912 PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
1913
1914 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
1915 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
1916 return PartEntry;
1917
1918 Entry2 = Entry2->Flink;
1919 }
1920 }
1921 }
1922
1923 Entry1 = Entry1->Flink;
1924 }
1925
1926 return NULL;
1927}

Referenced by IsVolumeBoot(), and IsVolumeSystem().

◆ GetPrevUnpartitionedEntry()

PPARTENTRY GetPrevUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 2998 of file partlist.c.

3000{
3001 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
3002 PPARTENTRY PrevPartEntry;
3003 PLIST_ENTRY ListHead;
3004
3005 if (PartEntry->LogicalPartition)
3006 ListHead = &DiskEntry->LogicalPartListHead;
3007 else
3008 ListHead = &DiskEntry->PrimaryPartListHead;
3009
3010 if (PartEntry->ListEntry.Blink != ListHead)
3011 {
3012 PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink,
3013 PARTENTRY,
3014 ListEntry);
3015 if (!PrevPartEntry->IsPartitioned)
3016 {
3018 return PrevPartEntry;
3019 }
3020 }
3021
3022 return NULL;
3023}

Referenced by DeleteGptPartition(), and DeleteMbrPartition().

◆ GetPrimaryPartitionCount()

ULONG GetPrimaryPartitionCount ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2635 of file partlist.c.

2637{
2639 PPARTENTRY PartEntry;
2640 ULONG Count = 0;
2641
2642 for (Entry = DiskEntry->PrimaryPartListHead.Flink;
2643 Entry != &DiskEntry->PrimaryPartListHead;
2644 Entry = Entry->Flink)
2645 {
2646 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
2647 if (PartEntry->IsPartitioned)
2648 Count++;
2649 }
2650
2651 return Count;
2652}

◆ GetVolumeExtents()

static VOID GetVolumeExtents ( _In_ HANDLE  VolumeHandle,
_In_ PVOLENTRY  VolumeEntry 
)
static

Definition at line 1675 of file partlist.c.

1678{
1679 DWORD dwBytesReturned = 0, dwLength, i;
1680 PVOLUME_DISK_EXTENTS pExtents;
1681 BOOL bResult;
1682 DWORD dwError;
1683
1684 dwLength = sizeof(VOLUME_DISK_EXTENTS);
1685 pExtents = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, dwLength);
1686 if (pExtents == NULL)
1687 return;
1688
1689 bResult = DeviceIoControl(VolumeHandle,
1691 NULL,
1692 0,
1693 pExtents,
1694 dwLength,
1695 &dwBytesReturned,
1696 NULL);
1697 if (!bResult)
1698 {
1699 dwError = GetLastError();
1700
1701 if (dwError != ERROR_MORE_DATA)
1702 {
1703 RtlFreeHeap(RtlGetProcessHeap(), 0, pExtents);
1704 return;
1705 }
1706 else
1707 {
1708 dwLength = sizeof(VOLUME_DISK_EXTENTS) + ((pExtents->NumberOfDiskExtents - 1) * sizeof(DISK_EXTENT));
1709 RtlFreeHeap(RtlGetProcessHeap(), 0, pExtents);
1710 pExtents = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, dwLength);
1711 if (pExtents == NULL)
1712 {
1713 return;
1714 }
1715
1716 bResult = DeviceIoControl(VolumeHandle,
1718 NULL,
1719 0,
1720 pExtents,
1721 dwLength,
1722 &dwBytesReturned,
1723 NULL);
1724 if (!bResult)
1725 {
1726 RtlFreeHeap(RtlGetProcessHeap(), 0, pExtents);
1727 return;
1728 }
1729 }
1730 }
1731
1732 for (i = 0; i < pExtents->NumberOfDiskExtents; i++)
1733 VolumeEntry->Size.QuadPart += pExtents->Extents[i].ExtentLength.QuadPart;
1734
1735 VolumeEntry->pExtents = pExtents;
1736}
#define ERROR_MORE_DATA
Definition: dderror.h:13
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
struct _VOLUME_DISK_EXTENTS VOLUME_DISK_EXTENTS
struct _DISK_EXTENT DISK_EXTENT
#define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
Definition: ntddvol.h:44
LARGE_INTEGER ExtentLength
Definition: ntddvol.h:50
DISK_EXTENT Extents[1]
Definition: ntddvol.h:55
ULONG NumberOfDiskExtents
Definition: ntddvol.h:54

Referenced by AddVolumeToList().

◆ GetVolumeFromPartition()

PVOLENTRY GetVolumeFromPartition ( _In_ PPARTENTRY  PartEntry)

Definition at line 3177 of file partlist.c.

3179{
3181 PVOLENTRY VolumeEntry;
3182 ULONG i;
3183
3184 if ((PartEntry == NULL) ||
3185 (PartEntry->DiskEntry == NULL))
3186 return NULL;
3187
3189 while (Entry != &VolumeListHead)
3190 {
3191 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
3192
3193 if (VolumeEntry->pExtents == NULL)
3194 return NULL;
3195
3196 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
3197 {
3198 if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
3199 {
3200 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
3201 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
3202 return VolumeEntry;
3203 }
3204 }
3205
3206 Entry = Entry->Flink;
3207 }
3208
3209 return NULL;
3210}
ULONG DiskNumber
Definition: ntddvol.h:48
LARGE_INTEGER StartingOffset
Definition: ntddvol.h:49

Referenced by clean_main().

◆ GetVolumeSize()

static VOID GetVolumeSize ( _In_ HANDLE  VolumeHandle,
_In_ PVOLENTRY  VolumeEntry 
)
static

Definition at line 1781 of file partlist.c.

1784{
1786 FILE_FS_FULL_SIZE_INFORMATION FullSizeInfo;
1789
1790 ZeroMemory(&FullSizeInfo, sizeof(FullSizeInfo));
1793 &FullSizeInfo,
1796 if (NT_SUCCESS(Status))
1797 {
1798 DPRINT("FullSizeInfo.TotalAllocationUnits %I64u\n", FullSizeInfo.TotalAllocationUnits.QuadPart);
1799 DPRINT("FullSizeInfo.SectorsPerAllocationUnit %lu\n", FullSizeInfo.SectorsPerAllocationUnit);
1800 DPRINT("FullSizeInfo.BytesPerSector %lu\n", FullSizeInfo.BytesPerSector);
1801
1802 VolumeEntry->TotalAllocationUnits.QuadPart = FullSizeInfo.TotalAllocationUnits.QuadPart;
1803 VolumeEntry->SectorsPerAllocationUnit = FullSizeInfo.SectorsPerAllocationUnit;
1804 VolumeEntry->BytesPerSector = FullSizeInfo.BytesPerSector;
1805 }
1806 else
1807 {
1808 ZeroMemory(&SizeInfo, sizeof(SizeInfo));
1811 &SizeInfo,
1814 if (NT_SUCCESS(Status))
1815 {
1816 DPRINT("SizeInfo.TotalAllocationUnits %I64u\n", SizeInfo.TotalAllocationUnits.QuadPart);
1817 DPRINT("SizeInfo.SectorsPerAllocationUnit %lu\n", SizeInfo.SectorsPerAllocationUnit);
1818 DPRINT("SizeInfo.BytesPerSector %lu\n", SizeInfo.BytesPerSector);
1819
1820 VolumeEntry->TotalAllocationUnits.QuadPart = SizeInfo.TotalAllocationUnits.QuadPart;
1821 VolumeEntry->SectorsPerAllocationUnit = SizeInfo.SectorsPerAllocationUnit;
1822 VolumeEntry->BytesPerSector = SizeInfo.BytesPerSector;
1823 }
1824 else
1825 {
1826 DPRINT("GetVolumeSize() failed!\n");
1827 }
1828 }
1829}
@ FileFsSizeInformation
Definition: from_kernel.h:221
#define ZeroMemory
Definition: minwinbase.h:31
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:270

Referenced by UpdateVolumeInfo().

◆ GetVolumeType()

static VOID GetVolumeType ( _In_ HANDLE  VolumeHandle,
_In_ PVOLENTRY  VolumeEntry 
)
static

Definition at line 1741 of file partlist.c.

1744{
1748
1751 &DeviceInfo,
1754 if (!NT_SUCCESS(Status))
1755 return;
1756
1757 switch (DeviceInfo.DeviceType)
1758 {
1759 case FILE_DEVICE_CD_ROM:
1761 VolumeEntry->VolumeType = VOLUME_TYPE_CDROM;
1762 break;
1763
1764 case FILE_DEVICE_DISK:
1766 if (DeviceInfo.Characteristics & FILE_REMOVABLE_MEDIA)
1767 VolumeEntry->VolumeType = VOLUME_TYPE_REMOVABLE;
1768 else
1769 VolumeEntry->VolumeType = VOLUME_TYPE_PARTITION;
1770 break;
1771
1772 default:
1773 VolumeEntry->VolumeType = VOLUME_TYPE_UNKNOWN;
1774 break;
1775 }
1776}
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:114
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:113
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:111
@ FileFsDeviceInformation
Definition: from_kernel.h:222
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:53
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:47
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:48
#define FILE_DEVICE_DISK
Definition: winioctl.h:52

Referenced by AddVolumeToList().

◆ InsertListAfter()

static VOID InsertListAfter ( _In_ PLIST_ENTRY  ListEntry,
_In_ PLIST_ENTRY  EntryToInsert 
)
static

Definition at line 2165 of file partlist.c.

2168{
2169 EntryToInsert->Blink = ListEntry;
2170 EntryToInsert->Flink = ListEntry->Flink;
2171 ListEntry->Flink->Blink = EntryToInsert;
2172 ListEntry->Flink = EntryToInsert;
2173}

Referenced by SortVolumeList().

◆ IsEmptyLayoutEntry()

static BOOLEAN IsEmptyLayoutEntry ( IN PPARTITION_INFORMATION_EX  PartitionInfo)
static

Definition at line 2604 of file partlist.c.

2606{
2607 if (PartitionInfo->StartingOffset.QuadPart == 0 &&
2608 PartitionInfo->PartitionLength.QuadPart == 0)
2609 {
2610 return TRUE;
2611 }
2612
2613 return FALSE;
2614}

◆ IsSamePrimaryLayoutEntry()

static BOOLEAN IsSamePrimaryLayoutEntry ( IN PPARTITION_INFORMATION_EX  PartitionInfo,
IN PDISKENTRY  DiskEntry,
IN PPARTENTRY  PartEntry 
)
static

Definition at line 2619 of file partlist.c.

2623{
2624 if ((PartitionInfo->StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector) &&
2625 (PartitionInfo->PartitionLength.QuadPart == PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector))
2626 {
2627 return TRUE;
2628 }
2629
2630 return FALSE;
2631}

◆ IsVolumeBoot()

static VOID IsVolumeBoot ( _In_ PVOLENTRY  VolumeEntry)
static

Definition at line 1986 of file partlist.c.

1988{
1989 WCHAR szSystemDir[MAX_PATH];
1990 PDISKENTRY DiskEntry;
1991 PPARTENTRY PartEntry;
1992
1993 DPRINT("IsVolumeBoot()\n");
1994
1995 VolumeEntry->IsBoot = FALSE;
1996
1997 if (VolumeEntry->DriveLetter == UNICODE_NULL)
1998 return;
1999
2000 GetSystemDirectoryW(szSystemDir,
2001 ARRAYSIZE(szSystemDir));
2002
2003 DPRINT("SystemDirectory: %S\n", szSystemDir);
2004 DPRINT("DriveLetter: %C\n", VolumeEntry->DriveLetter);
2005
2006 if (szSystemDir[0] == VolumeEntry->DriveLetter)
2007 {
2008 VolumeEntry->IsBoot = TRUE;
2009
2010 PartEntry = GetPartitionForVolume(VolumeEntry);
2011 if (PartEntry)
2012 PartEntry->IsBoot = TRUE;
2013
2014 DiskEntry = GetDiskForVolume(VolumeEntry);
2015 if (DiskEntry)
2016 DiskEntry->IsBoot = TRUE;
2017 }
2018}
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2331
BOOL IsBoot
Definition: diskpart.h:243
BOOL IsBoot
Definition: diskpart.h:180
static PDISKENTRY GetDiskForVolume(_In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1834
static PPARTENTRY GetPartitionForVolume(_In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1870

Referenced by AddVolumeToList().

◆ IsVolumeSystem()

static VOID IsVolumeSystem ( _In_ PVOLENTRY  VolumeEntry)
static

Definition at line 1932 of file partlist.c.

1934{
1935 WCHAR szSystemPartition[MAX_PATH];
1936 PPARTENTRY PartEntry;
1937 HKEY hKey;
1938 DWORD dwError, dwLength;
1939
1940 DPRINT("IsVolumeSystem()\n");
1941
1942 VolumeEntry->IsSystem = FALSE;
1943
1945 L"SYSTEM\\Setup",
1946 0,
1947 KEY_READ,
1948 &hKey);
1949 if (dwError != ERROR_SUCCESS)
1950 {
1951 DPRINT1("\n");
1952 return;
1953 }
1954
1955 dwLength = sizeof(szSystemPartition);
1956 dwError = RegQueryValueExW(hKey,
1957 L"SystemPartition",
1958 NULL,
1959 NULL,
1960 (PBYTE)szSystemPartition,
1961 &dwLength);
1963
1964 if (dwError != ERROR_SUCCESS)
1965 {
1966 DPRINT1("\n");
1967 return;
1968 }
1969
1970 DPRINT("SystemPartition: %S\n", szSystemPartition);
1971 DPRINT("DeviceName: %S\n", VolumeEntry->DeviceName);
1972
1973 if (_wcsnicmp(szSystemPartition, VolumeEntry->DeviceName, wcslen(szSystemPartition)) == 0)
1974 {
1975 VolumeEntry->IsSystem = TRUE;
1976
1977 PartEntry = GetPartitionForVolume(VolumeEntry);
1978 if (PartEntry)
1979 PartEntry->IsSystem = TRUE;
1980 }
1981}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:200
FxAutoRegKey hKey
#define KEY_READ
Definition: nt_native.h:1026
BOOL IsSystem
Definition: diskpart.h:179
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by AddVolumeToList().

◆ ReadLayoutBuffer()

VOID ReadLayoutBuffer ( _In_ HANDLE  FileHandle,
_In_ PDISKENTRY  DiskEntry 
)

Definition at line 1065 of file partlist.c.

1068{
1069 ULONG LayoutBufferSize;
1070 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
1073
1074 /* Allocate a layout buffer with 4 partition entries first */
1075 LayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
1076 ((4 - ANYSIZE_ARRAY) * sizeof(PARTITION_INFORMATION_EX));
1077 DiskEntry->LayoutBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
1079 LayoutBufferSize);
1080 if (DiskEntry->LayoutBuffer == NULL)
1081 {
1082 DPRINT1("Failed to allocate the disk layout buffer!\n");
1083 return;
1084 }
1085
1086 for (;;)
1087 {
1088 DPRINT("Buffer size: %lu\n", LayoutBufferSize);
1090 NULL,
1091 NULL,
1092 NULL,
1093 &Iosb,
1095 NULL,
1096 0,
1097 DiskEntry->LayoutBuffer,
1098 LayoutBufferSize);
1099 if (NT_SUCCESS(Status))
1100 break;
1101
1103 {
1104 DPRINT1("NtDeviceIoControlFile() failed (Status: 0x%08lx)\n", Status);
1105 return;
1106 }
1107
1108 LayoutBufferSize += 4 * sizeof(PARTITION_INFORMATION_EX);
1109 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
1111 DiskEntry->LayoutBuffer,
1112 LayoutBufferSize);
1113 if (NewLayoutBuffer == NULL)
1114 {
1115 DPRINT1("Failed to reallocate the disk layout buffer!\n");
1116 return;
1117 }
1118
1119 DiskEntry->LayoutBuffer = NewLayoutBuffer;
1120 }
1121}
#define IOCTL_DISK_GET_DRIVE_LAYOUT_EX
Definition: ntddk_ex.h:207
struct _PARTITION_INFORMATION_EX PARTITION_INFORMATION_EX
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define ANYSIZE_ARRAY
Definition: typedefs.h:46
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T) __WINE_ALLOC_SIZE(4) __WINE_DEALLOC(RtlFreeHeap

Referenced by AddDiskToList(), and CreateDisk().

◆ ReAllocateLayoutBuffer()

static BOOLEAN ReAllocateLayoutBuffer ( _In_ PDISKENTRY  DiskEntry)
static

Definition at line 2679 of file partlist.c.

2681{
2682 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
2683 ULONG NewPartitionCount;
2684 ULONG CurrentPartitionCount = 0;
2685 ULONG LayoutBufferSize;
2686 ULONG i;
2687
2688 DPRINT1("ReAllocateLayoutBuffer()\n");
2689
2690 NewPartitionCount = 4 + GetLogicalPartitionCount(DiskEntry) * 4;
2691
2692 if (DiskEntry->LayoutBuffer)
2693 CurrentPartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
2694
2695 DPRINT1("CurrentPartitionCount: %lu ; NewPartitionCount: %lu\n",
2696 CurrentPartitionCount, NewPartitionCount);
2697
2698 if (CurrentPartitionCount == NewPartitionCount)
2699 return TRUE;
2700
2701 LayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2702 ((NewPartitionCount - ANYSIZE_ARRAY) * sizeof(PARTITION_INFORMATION_EX));
2703 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
2705 DiskEntry->LayoutBuffer,
2706 LayoutBufferSize);
2707 if (NewLayoutBuffer == NULL)
2708 {
2709 DPRINT1("Failed to allocate the new layout buffer (size: %lu)\n", LayoutBufferSize);
2710 return FALSE;
2711 }
2712
2713 NewLayoutBuffer->PartitionCount = NewPartitionCount;
2714
2715 /* If the layout buffer grows, make sure the new (empty) entries are written to the disk */
2716 if (NewPartitionCount > CurrentPartitionCount)
2717 {
2718 for (i = CurrentPartitionCount; i < NewPartitionCount; i++)
2719 {
2720 NewLayoutBuffer->PartitionEntry[i].RewritePartition = TRUE;
2721 }
2722 }
2723
2724 DiskEntry->LayoutBuffer = NewLayoutBuffer;
2725
2726 return TRUE;
2727}
#define GetLogicalPartitionCount(DiskEntry)
Definition: partlist.c:2595

◆ RemoveVolume()

VOID RemoveVolume ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 3214 of file partlist.c.

3216{
3217 if (VolumeEntry == NULL)
3218 return;
3219
3220 if (VolumeEntry == CurrentVolume)
3222
3223 RemoveEntryList(&VolumeEntry->ListEntry);
3224
3225 if (VolumeEntry->pszLabel)
3226 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
3227
3228 if (VolumeEntry->pszFilesystem)
3229 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
3230
3231 if (VolumeEntry->pExtents)
3232 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
3233
3234 /* Release disk entry */
3235 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
3236}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by clean_main().

◆ ScanForUnpartitionedGptDiskSpace()

VOID ScanForUnpartitionedGptDiskSpace ( PDISKENTRY  DiskEntry)

Definition at line 921 of file partlist.c.

923{
924 ULONGLONG LastStartSector;
925 ULONGLONG LastSectorCount;
926 ULONGLONG LastUnusedSectorCount;
927 PPARTENTRY PartEntry;
928 PPARTENTRY NewPartEntry;
930
931 DPRINT("ScanForUnpartitionedGptDiskSpace()\n");
932
933#ifdef DUMP_PARTITION_LIST
934 DumpPartitionList(DiskEntry);
935#endif
936
937 if (IsListEmpty(&DiskEntry->PrimaryPartListHead))
938 {
939 DPRINT("No partitions!\n");
940
941 /* Create a partition table that represents the empty disk */
942 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
944 sizeof(PARTENTRY));
945 if (NewPartEntry == NULL)
946 return;
947
948 NewPartEntry->DiskEntry = DiskEntry;
949
950 NewPartEntry->IsPartitioned = FALSE;
951 NewPartEntry->StartSector.QuadPart = DiskEntry->StartSector.QuadPart;
952 NewPartEntry->SectorCount.QuadPart = DiskEntry->EndSector.QuadPart - DiskEntry->StartSector.QuadPart + 1;
953
954 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
955 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
956 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
957
958 NewPartEntry->FormatState = Unformatted;
959
961 &NewPartEntry->ListEntry);
962
963#ifdef DUMP_PARTITION_LIST
964 DumpPartitionList(DiskEntry);
965#endif
966
967 return;
968 }
969
970 /* Start at the first usable sector */
971 LastStartSector = DiskEntry->StartSector.QuadPart;
972 LastSectorCount = 0ULL;
973 LastUnusedSectorCount = 0ULL;
974
975 Entry = DiskEntry->PrimaryPartListHead.Flink;
976 while (Entry != &DiskEntry->PrimaryPartListHead)
977 {
978 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
979
980 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID) ||
981 PartEntry->SectorCount.QuadPart != 0ULL)
982 {
983 LastUnusedSectorCount =
984 PartEntry->StartSector.QuadPart - (LastStartSector + LastSectorCount);
985
986 if (PartEntry->StartSector.QuadPart > (LastStartSector + LastSectorCount) &&
987 LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
988 {
989 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
990
991 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
993 sizeof(PARTENTRY));
994 if (NewPartEntry == NULL)
995 return;
996
997 NewPartEntry->DiskEntry = DiskEntry;
998
999 NewPartEntry->IsPartitioned = FALSE;
1000 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
1001 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
1002 NewPartEntry->StartSector.QuadPart;
1003
1004 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
1005 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
1006 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
1007
1008 NewPartEntry->FormatState = Unformatted;
1009
1010 /* Insert the table into the list */
1011 InsertTailList(&PartEntry->ListEntry,
1012 &NewPartEntry->ListEntry);
1013 }
1014
1015 LastStartSector = PartEntry->StartSector.QuadPart;
1016 LastSectorCount = PartEntry->SectorCount.QuadPart;
1017 }
1018
1019 Entry = Entry->Flink;
1020 }
1021
1022 /* Check for trailing unpartitioned disk space */
1023 if ((LastStartSector + LastSectorCount) < DiskEntry->EndSector.QuadPart + 1)
1024 {
1025 LastUnusedSectorCount = AlignDown(DiskEntry->EndSector.QuadPart + 1 - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment);
1026
1027 if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
1028 {
1029 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount);
1030
1031 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
1033 sizeof(PARTENTRY));
1034 if (NewPartEntry == NULL)
1035 return;
1036
1037 NewPartEntry->DiskEntry = DiskEntry;
1038
1039 NewPartEntry->IsPartitioned = FALSE;
1040 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
1041 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
1042 NewPartEntry->StartSector.QuadPart;
1043
1044 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
1045 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
1046 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
1047
1048 NewPartEntry->FormatState = Unformatted;
1049
1050 /* Append the table to the list */
1052 &NewPartEntry->ListEntry);
1053 }
1054 }
1055
1056#ifdef DUMP_PARTITION_LIST
1057 DumpPartitionList(DiskEntry);
1058#endif
1059
1060 DPRINT("ScanForUnpartitionedGptDiskSpace() done\n");
1061}
#define ULL(a, b)
Definition: format_msg.c:27

Referenced by AddDiskToList(), and ConvertGPT().

◆ ScanForUnpartitionedMbrDiskSpace()

VOID ScanForUnpartitionedMbrDiskSpace ( PDISKENTRY  DiskEntry)

Definition at line 660 of file partlist.c.

662{
663 ULONGLONG StartSector, EndSector;
664 ULONGLONG LastStartSector;
665 ULONGLONG LastSectorCount;
666 ULONGLONG LastUnusedSectorCount;
667 PPARTENTRY PartEntry;
668 PPARTENTRY NewPartEntry;
670
671 DPRINT("ScanForUnpartitionedMbrDiskSpace()\n");
672
673 /* Calculate the disk sector limits */
674 /* Limit the SectorCount to 2^32 sectors for MBR disks */
675 StartSector = (ULONGLONG)DiskEntry->SectorAlignment;
676 EndSector = min(DiskEntry->SectorCount.QuadPart, 0x100000000) - 1;
677
678 if (IsListEmpty(&DiskEntry->PrimaryPartListHead))
679 {
680 DPRINT1("No primary partition!\n");
681
682 /* Create a partition table that represents the empty disk */
683 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
685 sizeof(PARTENTRY));
686 if (NewPartEntry == NULL)
687 return;
688
689 NewPartEntry->DiskEntry = DiskEntry;
690
691 NewPartEntry->IsPartitioned = FALSE;
692 NewPartEntry->StartSector.QuadPart = StartSector;
693 NewPartEntry->SectorCount.QuadPart = AlignDown(EndSector + 1, DiskEntry->SectorAlignment) -
694 NewPartEntry->StartSector.QuadPart;
695
696 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
697 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
698 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
699
700 NewPartEntry->FormatState = Unformatted;
701
703 &NewPartEntry->ListEntry);
704
705 return;
706 }
707
708 /* Start at the first usable sector */
709 LastStartSector = StartSector;
710 LastSectorCount = 0ULL;
711 LastUnusedSectorCount = 0ULL;
712
713 Entry = DiskEntry->PrimaryPartListHead.Flink;
714 while (Entry != &DiskEntry->PrimaryPartListHead)
715 {
716 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
717
718 if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED ||
719 PartEntry->SectorCount.QuadPart != 0ULL)
720 {
721 LastUnusedSectorCount =
722 PartEntry->StartSector.QuadPart - (LastStartSector + LastSectorCount);
723
724 if (PartEntry->StartSector.QuadPart > (LastStartSector + LastSectorCount) &&
725 LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
726 {
727 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
728
729 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
731 sizeof(PARTENTRY));
732 if (NewPartEntry == NULL)
733 return;
734
735 NewPartEntry->DiskEntry = DiskEntry;
736
737 NewPartEntry->IsPartitioned = FALSE;
738 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
739 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
740 NewPartEntry->StartSector.QuadPart;
741
742 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
743 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
744 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
745
746 NewPartEntry->FormatState = Unformatted;
747
748 /* Insert the table into the list */
749 InsertTailList(&PartEntry->ListEntry,
750 &NewPartEntry->ListEntry);
751 }
752
753 LastStartSector = PartEntry->StartSector.QuadPart;
754 LastSectorCount = PartEntry->SectorCount.QuadPart;
755 }
756
757 Entry = Entry->Flink;
758 }
759
760 /* Check for trailing unpartitioned disk space */
761 if ((LastStartSector + LastSectorCount) < (EndSector + 1))
762 {
763 LastUnusedSectorCount = AlignDown((EndSector + 1) - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment);
764
765 if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
766 {
767 DPRINT1("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount);
768
769 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
771 sizeof(PARTENTRY));
772 if (NewPartEntry == NULL)
773 return;
774
775 NewPartEntry->DiskEntry = DiskEntry;
776
777 NewPartEntry->IsPartitioned = FALSE;
778 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
779 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
780 NewPartEntry->StartSector.QuadPart;
781
782 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
783 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
784 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
785
786 NewPartEntry->FormatState = Unformatted;
787
788 /* Append the table to the list */
790 &NewPartEntry->ListEntry);
791 }
792 }
793
794 if (DiskEntry->ExtendedPartition != NULL)
795 {
796 if (IsListEmpty(&DiskEntry->LogicalPartListHead))
797 {
798 DPRINT1("No logical partition!\n");
799
800 /* Create a partition table entry that represents the empty extended partition */
801 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
803 sizeof(PARTENTRY));
804 if (NewPartEntry == NULL)
805 return;
806
807 NewPartEntry->DiskEntry = DiskEntry;
808 NewPartEntry->LogicalPartition = TRUE;
809
810 NewPartEntry->IsPartitioned = FALSE;
811 NewPartEntry->StartSector.QuadPart = DiskEntry->ExtendedPartition->StartSector.QuadPart + (ULONGLONG)DiskEntry->SectorAlignment;
812 NewPartEntry->SectorCount.QuadPart = DiskEntry->ExtendedPartition->SectorCount.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment;
813
814 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
815 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
816 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
817
818 NewPartEntry->FormatState = Unformatted;
819
821 &NewPartEntry->ListEntry);
822
823 return;
824 }
825
826 /* Start partition at head 1, cylinder 0 */
827 LastStartSector = DiskEntry->ExtendedPartition->StartSector.QuadPart + (ULONGLONG)DiskEntry->SectorAlignment;
828 LastSectorCount = 0ULL;
829 LastUnusedSectorCount = 0ULL;
830
831 Entry = DiskEntry->LogicalPartListHead.Flink;
832 while (Entry != &DiskEntry->LogicalPartListHead)
833 {
834 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
835
836 if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED ||
837 PartEntry->SectorCount.QuadPart != 0ULL)
838 {
839 LastUnusedSectorCount =
840 PartEntry->StartSector.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment - (LastStartSector + LastSectorCount);
841
842 if ((PartEntry->StartSector.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment) > (LastStartSector + LastSectorCount) &&
843 LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
844 {
845 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
846
847 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
849 sizeof(PARTENTRY));
850 if (NewPartEntry == NULL)
851 return;
852
853 NewPartEntry->DiskEntry = DiskEntry;
854 NewPartEntry->LogicalPartition = TRUE;
855
856 NewPartEntry->IsPartitioned = FALSE;
857 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
858 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
859 NewPartEntry->StartSector.QuadPart;
860
861 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
862 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
863 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
864
865 NewPartEntry->FormatState = Unformatted;
866
867 /* Insert the table into the list */
868 InsertTailList(&PartEntry->ListEntry,
869 &NewPartEntry->ListEntry);
870 }
871
872 LastStartSector = PartEntry->StartSector.QuadPart;
873 LastSectorCount = PartEntry->SectorCount.QuadPart;
874 }
875
876 Entry = Entry->Flink;
877 }
878
879 /* Check for trailing unpartitioned disk space */
880 if ((LastStartSector + LastSectorCount) < DiskEntry->ExtendedPartition->StartSector.QuadPart + DiskEntry->ExtendedPartition->SectorCount.QuadPart)
881 {
882 LastUnusedSectorCount = AlignDown(DiskEntry->ExtendedPartition->StartSector.QuadPart + DiskEntry->ExtendedPartition->SectorCount.QuadPart - (LastStartSector + LastSectorCount),
883 DiskEntry->SectorAlignment);
884
885 if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
886 {
887 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount);
888
889 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
891 sizeof(PARTENTRY));
892 if (NewPartEntry == NULL)
893 return;
894
895 NewPartEntry->DiskEntry = DiskEntry;
896 NewPartEntry->LogicalPartition = TRUE;
897
898 NewPartEntry->IsPartitioned = FALSE;
899 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
900 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
901 NewPartEntry->StartSector.QuadPart;
902
903 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
904 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
905 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
906
907 NewPartEntry->FormatState = Unformatted;
908
909 /* Append the table to the list */
911 &NewPartEntry->ListEntry);
912 }
913 }
914 }
915
916 DPRINT("ScanForUnpartitionedMbrDiskSpace() done\n");
917}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))

Referenced by AddDiskToList(), ConvertMBR(), CreateExtendedPartition(), and CreatePrimaryPartition().

◆ SortVolumeList()

static VOID SortVolumeList ( VOID  )
static

Definition at line 2178 of file partlist.c.

2179{
2180 PLIST_ENTRY Entry, TempEntry, LastInsertEntry;
2181 PVOLENTRY VolumeEntry;
2182 ULONG VolumeNumber;
2183
2184 /* Desired sort order: CDROM volumes, Partition volumes */
2185
2187 return;
2188
2189 /* Move CDROM volumes to the head of the list */
2190 LastInsertEntry = NULL;
2192 while (Entry != &VolumeListHead)
2193 {
2194 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2195
2196 if (VolumeEntry->VolumeType == VOLUME_TYPE_CDROM)
2197 {
2198 TempEntry = Entry;
2199 Entry = Entry->Blink;
2200
2201 RemoveEntryList(TempEntry);
2202 if (LastInsertEntry == NULL)
2203 InsertHeadList(&VolumeListHead, TempEntry);
2204 else
2205 InsertListAfter(LastInsertEntry, TempEntry);
2206 LastInsertEntry = TempEntry;
2207 }
2208
2209 Entry = Entry->Flink;
2210 }
2211
2212 /* Update the VolumeNumber */
2213 VolumeNumber = 0;
2215 while (Entry != &VolumeListHead)
2216 {
2217 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2218 VolumeEntry->VolumeNumber = VolumeNumber;
2219
2220 VolumeNumber++;
2221 Entry = Entry->Flink;
2222 }
2223}
#define InsertHeadList(ListHead, Entry)
static VOID InsertListAfter(_In_ PLIST_ENTRY ListEntry, _In_ PLIST_ENTRY EntryToInsert)
Definition: partlist.c:2165

Referenced by CreateVolumeList().

◆ SystemConfigurationDataQueryRoutine()

static NTSTATUS NTAPI SystemConfigurationDataQueryRoutine ( PWSTR  ValueName,
ULONG  ValueType,
PVOID  ValueData,
ULONG  ValueLength,
PVOID  Context,
PVOID  EntryContext 
)
static

Definition at line 311 of file partlist.c.

318{
319 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
321 ULONG i;
322
325 return STATUS_UNSUCCESSFUL;
326
327 FullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)ValueData;
328
329 /* Hm. Version and Revision are not set on Microsoft Windows XP... */
330#if 0
331 if (FullResourceDescriptor->PartialResourceList.Version != 1 ||
332 FullResourceDescriptor->PartialResourceList.Revision != 1)
333 return STATUS_UNSUCCESSFUL;
334#endif
335
336 for (i = 0; i < FullResourceDescriptor->PartialResourceList.Count; i++)
337 {
339 FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize % sizeof(CM_INT13_DRIVE_PARAMETER) != 0)
340 continue;
341
342 *Int13Drives = (CM_INT13_DRIVE_PARAMETER*)RtlAllocateHeap(RtlGetProcessHeap(), 0,
343 FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize);
344 if (*Int13Drives == NULL)
345 return STATUS_NO_MEMORY;
346
347 memcpy(*Int13Drives,
348 &FullResourceDescriptor->PartialResourceList.PartialDescriptors[i + 1],
349 FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize);
350 return STATUS_SUCCESS;
351 }
352
353 return STATUS_UNSUCCESSFUL;
354}
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ UpdateGptDiskLayout()

VOID UpdateGptDiskLayout ( _In_ PDISKENTRY  DiskEntry,
_In_ BOOL  DeleteEntry 
)

Definition at line 2908 of file partlist.c.

2911{
2912 PLIST_ENTRY ListEntry;
2913 PPARTENTRY PartEntry;
2915 ULONG Count, Index;
2916
2917 DPRINT("UpdateGptDiskLayout()\n");
2918
2919 /* Count used partition entries */
2920 Count = 0;
2921 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2922 ListEntry != &DiskEntry->PrimaryPartListHead;
2923 ListEntry = ListEntry->Flink)
2924 {
2925 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2926
2927 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
2928 Count++;
2929 }
2930
2931 DPRINT("Used partition entries: %lu\n", Count);
2932
2933 if (DeleteEntry)
2934 Count++;
2935
2936 /* Reallocate the layout buffer */
2937 if (Count != DiskEntry->LayoutBuffer->PartitionCount)
2938 {
2939 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
2940 ULONG NewLayoutBufferSize;
2941
2942 NewLayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2944 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
2946 DiskEntry->LayoutBuffer,
2947 NewLayoutBufferSize);
2948 if (NewLayoutBuffer == NULL)
2949 {
2950 DPRINT1("Failed to allocate the new layout buffer (size: %lu)\n", NewLayoutBufferSize);
2951 return;
2952 }
2953
2954 NewLayoutBuffer->PartitionCount = Count;
2955 DiskEntry->LayoutBuffer = NewLayoutBuffer;
2956 }
2957
2958 /* Fill the new layout buffer */
2959 Index = 0;
2960 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2961 ListEntry != &DiskEntry->PrimaryPartListHead;
2962 ListEntry = ListEntry->Flink)
2963 {
2964 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2965
2966 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
2967 {
2968 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2969 PartEntry->PartitionIndex = Index;
2970
2971 DPRINT("Updating primary partition entry %lu\n", Index);
2972 PartitionInfo->PartitionStyle = PARTITION_STYLE_GPT;
2973 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2974 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2975 PartitionInfo->PartitionNumber = Index + 1;
2976 PartitionInfo->RewritePartition = TRUE;
2977 CopyMemory(&PartitionInfo->Gpt.PartitionType, &PartEntry->Gpt.PartitionType, sizeof(GUID));
2978 CopyMemory(&PartitionInfo->Gpt.PartitionId, &PartEntry->Gpt.PartitionId, sizeof(GUID));
2979 PartitionInfo->Gpt.Attributes = PartEntry->Gpt.Attributes;
2980 ZeroMemory(&PartitionInfo->Gpt.Name, 36 * sizeof(WCHAR)); /* ??? */
2981
2982 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
2983
2984 Index++;
2985 }
2986 }
2987
2988 if (DeleteEntry)
2989 {
2990 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2992 PartitionInfo->RewritePartition = TRUE;
2993 }
2994}

Referenced by CreateEfiPartition(), CreateMsrPartition(), CreatePrimaryGptPartition(), DeleteGptPartition(), gpt_main(), setid_main(), and UniqueIdDisk().

◆ UpdateMbrDiskLayout()

VOID UpdateMbrDiskLayout ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2731 of file partlist.c.

2733{
2736 PLIST_ENTRY ListEntry;
2737 PPARTENTRY PartEntry;
2738 LARGE_INTEGER HiddenSectors64;
2739 ULONG Index;
2741
2742 DPRINT("UpdateMbrDiskLayout()\n");
2743
2744 /* Resize the layout buffer if necessary */
2745 if (ReAllocateLayoutBuffer(DiskEntry) == FALSE)
2746 {
2747 DPRINT("ReAllocateLayoutBuffer() failed.\n");
2748 return;
2749 }
2750
2751 DiskEntry->LayoutBuffer->PartitionStyle = PARTITION_STYLE_MBR;
2752
2753 /* Update the primary partition table */
2754 Index = 0;
2755 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2756 ListEntry != &DiskEntry->PrimaryPartListHead;
2757 ListEntry = ListEntry->Flink)
2758 {
2759 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2760
2761 if (PartEntry->IsPartitioned)
2762 {
2764
2765 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2766 PartEntry->PartitionIndex = Index;
2767
2768 /* Reset the current partition number only for newly-created (unmounted) partitions */
2769 if (PartEntry->New)
2770 PartEntry->PartitionNumber = 0;
2771
2773
2774 if (!IsSamePrimaryLayoutEntry(PartitionInfo, DiskEntry, PartEntry))
2775 {
2776 DPRINT1("Updating primary partition entry %lu\n", Index);
2777
2778 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2779 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2780 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2781 PartitionInfo->Mbr.HiddenSectors = PartEntry->StartSector.LowPart;
2782 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
2783 PartitionInfo->Mbr.PartitionType = PartEntry->Mbr.PartitionType;
2784 PartitionInfo->Mbr.BootIndicator = PartEntry->Mbr.BootIndicator;
2785 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->Mbr.PartitionType);
2786 PartitionInfo->RewritePartition = TRUE;
2787 }
2788
2789 if (!IsContainerPartition(PartEntry->Mbr.PartitionType))
2791
2792 Index++;
2793 }
2794 }
2795
2796 ASSERT(Index <= 4);
2797
2798 /* Update the logical partition table */
2799 Index = 4;
2800 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
2801 ListEntry != &DiskEntry->LogicalPartListHead;
2802 ListEntry = ListEntry->Flink)
2803 {
2804 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2805
2806 if (PartEntry->IsPartitioned)
2807 {
2809
2810 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2811 PartEntry->PartitionIndex = Index;
2812
2813 /* Reset the current partition number only for newly-created (unmounted) partitions */
2814 if (PartEntry->New)
2815 PartEntry->PartitionNumber = 0;
2816
2818
2819 DPRINT1("Updating logical partition entry %lu\n", Index);
2820
2821 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2822 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2823 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2824 PartitionInfo->Mbr.HiddenSectors = DiskEntry->SectorAlignment;
2825 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
2826 PartitionInfo->Mbr.PartitionType = PartEntry->Mbr.PartitionType;
2827 PartitionInfo->Mbr.BootIndicator = FALSE;
2828 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->Mbr.PartitionType);
2829 PartitionInfo->RewritePartition = TRUE;
2830
2831 /* Fill the link entry of the previous partition entry */
2832 if (LinkInfo != NULL)
2833 {
2835 LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
2836 LinkInfo->PartitionLength.QuadPart = (PartEntry->StartSector.QuadPart + DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
2837 HiddenSectors64.QuadPart = PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment - DiskEntry->ExtendedPartition->StartSector.QuadPart;
2838 LinkInfo->Mbr.HiddenSectors = HiddenSectors64.LowPart;
2839 LinkInfo->PartitionNumber = 0;
2841 LinkInfo->Mbr.BootIndicator = FALSE;
2842 LinkInfo->Mbr.RecognizedPartition = FALSE;
2843 LinkInfo->RewritePartition = TRUE;
2844 }
2845
2846 /* Save a pointer to the link entry of the current partition entry */
2847 LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1];
2848
2850 Index += 4;
2851 }
2852 }
2853
2854 /* Wipe unused primary partition entries */
2855 for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++)
2856 {
2857 DPRINT1("Primary partition entry %lu\n", Index);
2858
2859 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2860
2862 {
2863 DPRINT1("Wiping primary partition entry %lu\n", Index);
2864
2865 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2866 PartitionInfo->StartingOffset.QuadPart = 0;
2867 PartitionInfo->PartitionLength.QuadPart = 0;
2868 PartitionInfo->Mbr.HiddenSectors = 0;
2869 PartitionInfo->PartitionNumber = 0;
2870 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
2871 PartitionInfo->Mbr.BootIndicator = FALSE;
2872 PartitionInfo->Mbr.RecognizedPartition = FALSE;
2873 PartitionInfo->RewritePartition = TRUE;
2874 }
2875 }
2876
2877 /* Wipe unused logical partition entries */
2878 for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++)
2879 {
2880 if (Index % 4 >= 2)
2881 {
2882 DPRINT1("Logical partition entry %lu\n", Index);
2883
2884 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2885
2887 {
2888 DPRINT1("Wiping partition entry %lu\n", Index);
2889
2890 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2891 PartitionInfo->StartingOffset.QuadPart = 0;
2892 PartitionInfo->PartitionLength.QuadPart = 0;
2893 PartitionInfo->Mbr.HiddenSectors = 0;
2894 PartitionInfo->PartitionNumber = 0;
2895 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
2896 PartitionInfo->Mbr.BootIndicator = FALSE;
2897 PartitionInfo->Mbr.RecognizedPartition = FALSE;
2898 PartitionInfo->RewritePartition = TRUE;
2899 }
2900 }
2901 }
2902
2903 DiskEntry->Dirty = TRUE;
2904}
#define PARTITION_EXTENDED
Definition: part_mbr.h:55
#define GetPrimaryPartitionCount(DiskEntry)
Definition: partlist.c:2592
BOOLEAN New
Definition: partlist.h:85
ULONG OnDiskPartitionNumber
Definition: partlist.h:74
LARGE_INTEGER StartingOffset
Definition: imports.h:221
PARTITION_STYLE PartitionStyle
Definition: imports.h:220
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
LARGE_INTEGER PartitionLength
Definition: imports.h:222
$ULONG LowPart
Definition: ntbasedef.h:581
static BOOLEAN IsSamePrimaryLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo, IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry)
Definition: partlist.c:2619
static BOOLEAN IsEmptyLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo)
Definition: partlist.c:2604
static BOOLEAN ReAllocateLayoutBuffer(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2679
ULONG LowPart
Definition: typedefs.h:106
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

Referenced by active_main(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryMbrPartition(), DeleteMbrPartition(), inactive_main(), setid_main(), and UniqueIdDisk().

◆ UpdateVolumeInfo()

VOID UpdateVolumeInfo ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 2296 of file partlist.c.

2298{
2301 WCHAR szVolumeName[MAX_PATH + 1];
2302 WCHAR szFilesystem[MAX_PATH + 1];
2303 WCHAR szRootPath[12];
2306 DWORD dwError;
2308
2309
2310 _swprintf(szRootPath, L"%c:\\", VolumeEntry->DriveLetter);
2311
2312 if (!RtlDosPathNameToNtPathName_U(szRootPath,
2313 &Name,
2314 NULL,
2315 NULL))
2316 {
2318 return;
2319 }
2320
2322 &Name,
2323 0,
2324 NULL,
2325 NULL);
2326
2330 &Iosb,
2331 0,
2333 if (NT_SUCCESS(Status))
2334 {
2335 GetVolumeSize(VolumeHandle, VolumeEntry);
2336 VolumeEntry->Size.QuadPart = VolumeEntry->TotalAllocationUnits.QuadPart *
2337 VolumeEntry->SectorsPerAllocationUnit *
2338 VolumeEntry->BytesPerSector;
2340 }
2342
2343 if (VolumeEntry->pszLabel)
2344 {
2345 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2346 VolumeEntry->pszLabel = NULL;
2347 }
2348
2349 if (VolumeEntry->pszFilesystem)
2350 {
2351 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2352 VolumeEntry->pszFilesystem = NULL;
2353 }
2354
2355 if (GetVolumeInformationW(VolumeEntry->VolumeName,
2356 szVolumeName,
2357 MAX_PATH + 1,
2358 &VolumeEntry->SerialNumber,
2359 NULL,
2360 NULL,
2361 szFilesystem,
2362 MAX_PATH + 1))
2363 {
2364 VolumeEntry->pszLabel = RtlAllocateHeap(RtlGetProcessHeap(),
2365 0,
2366 (wcslen(szVolumeName) + 1) * sizeof(WCHAR));
2367 if (VolumeEntry->pszLabel)
2368 wcscpy(VolumeEntry->pszLabel, szVolumeName);
2369
2370 VolumeEntry->pszFilesystem = RtlAllocateHeap(RtlGetProcessHeap(),
2371 0,
2372 (wcslen(szFilesystem) + 1) * sizeof(WCHAR));
2373 if (VolumeEntry->pszFilesystem)
2374 wcscpy(VolumeEntry->pszFilesystem, szFilesystem);
2375 VolumeEntry->VolumeStatus = VOLUME_STATUS_HEALTHY;
2376 }
2377 else
2378 {
2379 dwError = GetLastError();
2380 if (dwError == ERROR_UNRECOGNIZED_VOLUME)
2381 {
2382 VolumeEntry->pszFilesystem = RtlAllocateHeap(RtlGetProcessHeap(),
2383 0,
2384 (3 + 1) * sizeof(WCHAR));
2385 if (VolumeEntry->pszFilesystem)
2386 wcscpy(VolumeEntry->pszFilesystem, L"RAW");
2387 VolumeEntry->SerialNumber = 0;
2388 VolumeEntry->SectorsPerAllocationUnit = 1;
2389 VolumeEntry->BytesPerSector = 512;
2390 VolumeEntry->VolumeType = VOLUME_TYPE_PARTITION;
2391 VolumeEntry->VolumeStatus = VOLUME_STATUS_HEALTHY;
2392 }
2393 else if (dwError == ERROR_NOT_READY)
2394 {
2395 VolumeEntry->VolumeStatus = VOLUME_STATUS_NO_MEDIA;
2396 VolumeEntry->Size.QuadPart = 0;
2397 }
2398 }
2399}
#define SetLastError(x)
Definition: compat.h:752
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
static VOID GetVolumeSize(_In_ HANDLE VolumeHandle, _In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:1781
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228

Referenced by PrintVolume().

◆ WriteGptPartitions()

NTSTATUS WriteGptPartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2527 of file partlist.c.

2529{
2537
2538 DPRINT("WriteGptPartitions() Disk: %lu\n", DiskEntry->DiskNumber);
2539
2540 /* If the disk is not dirty, there is nothing to do */
2541 if (!DiskEntry->Dirty)
2542 return STATUS_SUCCESS;
2543
2545 L"\\Device\\Harddisk%lu\\Partition0",
2546 DiskEntry->DiskNumber);
2548
2550 &Name,
2552 NULL,
2553 NULL);
2554
2558 &Iosb,
2559 0,
2561 if (!NT_SUCCESS(Status))
2562 {
2563 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
2564 return Status;
2565 }
2566
2567 //
2568 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
2569 // the disk in MBR or GPT format in case the disk was not initialized!!
2570 // For this we must ask the user which format to use.
2571 //
2572
2573 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
2574 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2575 ((DiskEntry->LayoutBuffer->PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
2577 NULL,
2578 NULL,
2579 NULL,
2580 &Iosb,
2582 DiskEntry->LayoutBuffer,
2583 BufferSize,
2584 DiskEntry->LayoutBuffer,
2585 BufferSize);
2587
2588 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT_EX call succeeded */
2589 if (!NT_SUCCESS(Status))
2590 {
2591 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT_EX failed (Status 0x%08lx)\n", Status);
2592 return Status;
2593 }
2594
2595 /* The layout has been successfully updated, the disk is not dirty anymore */
2596 DiskEntry->Dirty = FALSE;
2597
2598 return Status;
2599}
#define BufferSize
Definition: mmc.h:75
_In_ ULONG BufferSize
Definition: dispmprt.h:490
#define IOCTL_DISK_SET_DRIVE_LAYOUT_EX
Definition: ntdddisk.h:208
IN HANDLE DstPath
Definition: fsutil.h:81

Referenced by CreateEfiPartition(), CreateMsrPartition(), CreatePrimaryGptPartition(), DeleteGptPartition(), gpt_main(), setid_main(), and UniqueIdDisk().

◆ WriteMbrPartitions()

NTSTATUS WriteMbrPartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2403 of file partlist.c.

2405{
2413 ULONG PartitionCount;
2414 PLIST_ENTRY ListEntry;
2415 PPARTENTRY PartEntry;
2417
2418 DPRINT("WriteMbrPartitions() Disk: %lu\n", DiskEntry->DiskNumber);
2419
2420 /* If the disk is not dirty, there is nothing to do */
2421 if (!DiskEntry->Dirty)
2422 return STATUS_SUCCESS;
2423
2425 L"\\Device\\Harddisk%lu\\Partition0",
2426 DiskEntry->DiskNumber);
2428
2430 &Name,
2432 NULL,
2433 NULL);
2434
2438 &Iosb,
2439 0,
2441 if (!NT_SUCCESS(Status))
2442 {
2443 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
2444 return Status;
2445 }
2446
2447 //
2448 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
2449 // the disk in MBR or GPT format in case the disk was not initialized!!
2450 // For this we must ask the user which format to use.
2451 //
2452
2453 /* Save the original partition count to be restored later (see comment below) */
2454 PartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
2455
2456 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
2457 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2458 ((PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
2460 NULL,
2461 NULL,
2462 NULL,
2463 &Iosb,
2465 DiskEntry->LayoutBuffer,
2466 BufferSize,
2467 DiskEntry->LayoutBuffer,
2468 BufferSize);
2470
2471 /*
2472 * IOCTL_DISK_SET_DRIVE_LAYOUT calls IoWritePartitionTable(), which converts
2473 * DiskEntry->LayoutBuffer->PartitionCount into a partition *table* count,
2474 * where such a table is expected to enumerate up to 4 partitions:
2475 * partition *table* count == ROUND_UP(PartitionCount, 4) / 4 .
2476 * Due to this we need to restore the original PartitionCount number.
2477 */
2478 DiskEntry->LayoutBuffer->PartitionCount = PartitionCount;
2479
2480 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT call succeeded */
2481 if (!NT_SUCCESS(Status))
2482 {
2483 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status);
2484 return Status;
2485 }
2486
2487 /* Update the partition numbers */
2488
2489 /* Update the primary partition table */
2490 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2491 ListEntry != &DiskEntry->PrimaryPartListHead;
2492 ListEntry = ListEntry->Flink)
2493 {
2494 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2495
2496 if (PartEntry->IsPartitioned)
2497 {
2499 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
2500 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
2501 }
2502 }
2503
2504 /* Update the logical partition table */
2505 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
2506 ListEntry != &DiskEntry->LogicalPartListHead;
2507 ListEntry = ListEntry->Flink)
2508 {
2509 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2510
2511 if (PartEntry->IsPartitioned)
2512 {
2514 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
2515 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
2516 }
2517 }
2518
2519 /* The layout has been successfully updated, the disk is not dirty anymore */
2520 DiskEntry->Dirty = FALSE;
2521
2522 return Status;
2523}

Referenced by active_main(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryMbrPartition(), DeleteMbrPartition(), inactive_main(), setid_main(), and UniqueIdDisk().

Variable Documentation

◆ BiosDiskListHead

LIST_ENTRY BiosDiskListHead

◆ CurrentDisk

◆ CurrentPartition

PPARTENTRY CurrentPartition = NULL

Definition at line 76 of file partlist.c.

Referenced by CreatePartitionList(), and DestroyPartitionList().

◆ CurrentVolume

◆ DiskListHead

◆ VolumeListHead