ReactOS 0.4.15-dev-7918-g2a2556c
partition.c File Reference
#include "partmgr.h"
Include dependency graph for partition.c:

Go to the source code of this file.

Functions

NTSTATUS PartitionCreateDevice (_In_ PDEVICE_OBJECT FDObject, _In_ PPARTITION_INFORMATION_EX PartitionEntry, _In_ UINT32 PdoNumber, _In_ PARTITION_STYLE PartitionStyle, _Out_ PDEVICE_OBJECT *PDO)
 
static NTSTATUS PartitionHandleStartDevice (_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
 
NTSTATUS PartitionHandleRemove (_In_ PPARTITION_EXTENSION PartExt, _In_ BOOLEAN FinalRemove)
 
static NTSTATUS PartitionHandleDeviceRelations (_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
 
static NTSTATUS PartitionHandleQueryId (_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
 
static NTSTATUS PartitionHandleQueryCapabilities (_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
 
NTSTATUS PartitionHandlePnp (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
NTSTATUS PartitionHandleDeviceControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 

Variables

static const WCHAR PartitionSymLinkFormat [] = L"\\Device\\Harddisk%u\\Partition%u"
 

Function Documentation

◆ PartitionCreateDevice()

NTSTATUS PartitionCreateDevice ( _In_ PDEVICE_OBJECT  FDObject,
_In_ PPARTITION_INFORMATION_EX  PartitionEntry,
_In_ UINT32  PdoNumber,
_In_ PARTITION_STYLE  PartitionStyle,
_Out_ PDEVICE_OBJECT PDO 
)

Definition at line 15 of file partition.c.

21{
22 PAGED_CODE();
23
24 static UINT32 HarddiskVolumeNextId = 1; // this is 1-based
25
26 WCHAR nameBuf[64];
27 UNICODE_STRING deviceName;
28
29 // create the device object
30
31 swprintf(nameBuf, L"\\Device\\HarddiskVolume%u", HarddiskVolumeNextId++);
32 RtlCreateUnicodeString(&deviceName, nameBuf);
33
34 PDEVICE_OBJECT partitionDevice;
35 NTSTATUS status = IoCreateDevice(FDObject->DriverObject,
36 sizeof(PARTITION_EXTENSION),
37 &deviceName,
40 FALSE,
41 &partitionDevice);
42
43 if (!NT_SUCCESS(status))
44 {
45 ERR("Unable to create device object %wZ\n", &deviceName);
46 return status;
47 }
48
49 INFO("Created device object %p %wZ\n", partitionDevice, &deviceName);
50
51 PPARTITION_EXTENSION partExt = partitionDevice->DeviceExtension;
52 RtlZeroMemory(partExt, sizeof(*partExt));
53
54 partitionDevice->StackSize = FDObject->StackSize;
55 partitionDevice->Flags |= DO_DIRECT_IO;
56
57 if (PartitionStyle == PARTITION_STYLE_MBR)
58 {
59 partExt->Mbr.PartitionType = PartitionEntry->Mbr.PartitionType;
60 partExt->Mbr.BootIndicator = PartitionEntry->Mbr.BootIndicator;
61 partExt->Mbr.HiddenSectors = PartitionEntry->Mbr.HiddenSectors;
62 }
63 else
64 {
65 partExt->Gpt.PartitionType = PartitionEntry->Gpt.PartitionType;
66 partExt->Gpt.PartitionId = PartitionEntry->Gpt.PartitionType;
67 partExt->Gpt.Attributes = PartitionEntry->Gpt.Attributes;
68
69 RtlCopyMemory(partExt->Gpt.Name, PartitionEntry->Gpt.Name, sizeof(partExt->Gpt.Name));
70 }
71
72 partExt->DeviceName = deviceName;
73 partExt->StartingOffset = PartitionEntry->StartingOffset.QuadPart;
74 partExt->PartitionLength = PartitionEntry->PartitionLength.QuadPart;
75 partExt->OnDiskNumber = PartitionEntry->PartitionNumber; // the "physical" partition number
76 partExt->DetectedNumber = PdoNumber; // counts only partitions with PDO created
77
78 partExt->DeviceObject = partitionDevice;
79 partExt->LowerDevice = FDObject;
80
81 partitionDevice->Flags &= ~DO_DEVICE_INITIALIZING;
82
83 *PDO = partitionDevice;
84
85 return status;
86}
#define PAGED_CODE()
unsigned int UINT32
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: debug.h:110
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf
Definition: precomp.h:40
#define INFO
Definition: debug.h:89
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
@ PARTITION_STYLE_MBR
Definition: imports.h:201
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
PVOID DeviceExtension
Definition: env_spec_w32.h:418
struct _PARTITION_EXTENSION::@1319::@1322 Mbr
UINT64 StartingOffset
Definition: partmgr.h:72
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:69
struct _PARTITION_EXTENSION::@1319::@1321 Gpt
UINT32 DetectedNumber
Definition: partmgr.h:76
UNICODE_STRING DeviceName
Definition: partmgr.h:100
UINT64 PartitionLength
Definition: partmgr.h:73
UINT32 OnDiskNumber
Definition: partmgr.h:77
PDEVICE_OBJECT DeviceObject
Definition: partmgr.h:68
Definition: ps.c:97
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PartMgrUpdatePartitionDevices().

◆ PartitionHandleDeviceControl()

NTSTATUS PartitionHandleDeviceControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 449 of file partition.c.

452{
454 PPARTITION_EXTENSION partExt = DeviceObject->DeviceExtension;
455 PFDO_EXTENSION fdoExtension = partExt->LowerDevice->DeviceExtension;
457
458 ASSERT(!partExt->IsFDO);
459
460 if (!partExt->IsEnumerated)
461 {
462 Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
465 }
466
467 switch (ioStack->Parameters.DeviceIoControl.IoControlCode)
468 {
469 // disk stuff
471 {
473 {
475 break;
476 }
477
478 PartMgrAcquireLayoutLock(fdoExtension);
479
480 // not supported on anything other than MBR
481 if (fdoExtension->DiskData.PartitionStyle != PARTITION_STYLE_MBR)
482 {
484 PartMgrReleaseLayoutLock(fdoExtension);
485 break;
486 }
487
488 PPARTITION_INFORMATION partInfo = Irp->AssociatedIrp.SystemBuffer;
489
490 *partInfo = (PARTITION_INFORMATION){
491 .PartitionType = partExt->Mbr.PartitionType,
492 .StartingOffset.QuadPart = partExt->StartingOffset,
493 .PartitionLength.QuadPart = partExt->PartitionLength,
494 .HiddenSectors = partExt->Mbr.HiddenSectors,
495 .PartitionNumber = partExt->DetectedNumber,
496 .BootIndicator = partExt->Mbr.BootIndicator,
497 .RecognizedPartition = partExt->Mbr.RecognizedPartition,
498 .RewritePartition = FALSE,
499 };
500
501 PartMgrReleaseLayoutLock(fdoExtension);
502
503 Irp->IoStatus.Information = sizeof(*partInfo);
505 break;
506 }
508 {
510 {
512 break;
513 }
514
515 PPARTITION_INFORMATION_EX partInfoEx = Irp->AssociatedIrp.SystemBuffer;
516
517 PartMgrAcquireLayoutLock(fdoExtension);
518
519 *partInfoEx = (PARTITION_INFORMATION_EX){
521 .PartitionLength.QuadPart = partExt->PartitionLength,
522 .PartitionNumber = partExt->DetectedNumber,
523 .PartitionStyle = fdoExtension->DiskData.PartitionStyle,
524 .RewritePartition = FALSE,
525 };
526
527 if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
528 {
529 partInfoEx->Mbr = (PARTITION_INFORMATION_MBR){
530 .PartitionType = partExt->Mbr.PartitionType,
531 .HiddenSectors = partExt->Mbr.HiddenSectors,
532 .BootIndicator = partExt->Mbr.BootIndicator,
533 .RecognizedPartition = partExt->Mbr.RecognizedPartition,
534 };
535 }
536 else
537 {
538 partInfoEx->Gpt = (PARTITION_INFORMATION_GPT){
539 .PartitionType = partExt->Gpt.PartitionType,
540 .PartitionId = partExt->Gpt.PartitionId,
541 .Attributes = partExt->Gpt.Attributes,
542 };
543
544 RtlCopyMemory(partInfoEx->Gpt.Name,
545 partExt->Gpt.Name,
546 sizeof(partInfoEx->Gpt.Name));
547 }
548
549 PartMgrReleaseLayoutLock(fdoExtension);
550
551 Irp->IoStatus.Information = sizeof(*partInfoEx);
553 break;
554 }
556 {
557 PSET_PARTITION_INFORMATION inputBuffer = Irp->AssociatedIrp.SystemBuffer;
558 if (!VerifyIrpInBufferSize(Irp, sizeof(*inputBuffer)))
559 {
561 break;
562 }
563
564 PartMgrAcquireLayoutLock(fdoExtension);
565
566 // these functions use on disk numbers, not detected ones
568 fdoExtension->DiskData.BytesPerSector,
569 partExt->OnDiskNumber,
570 inputBuffer->PartitionType);
571
572 if (NT_SUCCESS(status))
573 {
574 partExt->Mbr.PartitionType = inputBuffer->PartitionType;
575 }
576
577 PartMgrReleaseLayoutLock(fdoExtension);
578
579 Irp->IoStatus.Information = 0;
580 break;
581 }
583 {
584 PSET_PARTITION_INFORMATION_EX inputBuffer = Irp->AssociatedIrp.SystemBuffer;
585 if (!VerifyIrpInBufferSize(Irp, sizeof(*inputBuffer)))
586 {
588 break;
589 }
590
591 PartMgrAcquireLayoutLock(fdoExtension);
592
593 // these functions use on disk numbers, not detected ones
595 partExt->OnDiskNumber,
596 inputBuffer);
597
598 if (NT_SUCCESS(status))
599 {
600 if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
601 {
602 partExt->Mbr.PartitionType = inputBuffer->Mbr.PartitionType;
603 }
604 else
605 {
606 partExt->Gpt.PartitionType = inputBuffer->Gpt.PartitionType;
607 partExt->Gpt.PartitionId = inputBuffer->Gpt.PartitionId;
608 partExt->Gpt.Attributes = inputBuffer->Gpt.Attributes;
609
610 RtlMoveMemory(partExt->Gpt.Name,
611 inputBuffer->Gpt.Name,
612 sizeof(partExt->Gpt.Name));
613 }
614 }
615
616 PartMgrReleaseLayoutLock(fdoExtension);
617
618 Irp->IoStatus.Information = 0;
619 break;
620 }
622 {
623 PGET_LENGTH_INFORMATION lengthInfo = Irp->AssociatedIrp.SystemBuffer;
624 if (!VerifyIrpOutBufferSize(Irp, sizeof(*lengthInfo)))
625 {
627 break;
628 }
629
630 PartMgrAcquireLayoutLock(fdoExtension);
631
632 lengthInfo->Length.QuadPart = partExt->PartitionLength;
633
634 PartMgrReleaseLayoutLock(fdoExtension);
635
637 Irp->IoStatus.Information = sizeof(*lengthInfo);
638 break;
639 }
641 {
642 PVERIFY_INFORMATION verifyInfo = Irp->AssociatedIrp.SystemBuffer;
643 if (!VerifyIrpInBufferSize(Irp, sizeof(*verifyInfo)))
644 {
646 break;
647 }
648
649 // Partition device should just adjust the starting offset
650 verifyInfo->StartingOffset.QuadPart += partExt->StartingOffset;
652 }
654 {
655 fdoExtension->LayoutValid = FALSE;
657
659 break;
660 }
662 {
664 }
665 // volume stuff (most of that should be in volmgr.sys one it is implemented)
667 {
668 PVOLUME_DISK_EXTENTS volExts = Irp->AssociatedIrp.SystemBuffer;
669
670 // we fill only one extent entry so sizeof(*volExts) is enough
671 if (!VerifyIrpOutBufferSize(Irp, sizeof(*volExts)))
672 {
674 break;
675 }
676
677 PartMgrAcquireLayoutLock(fdoExtension);
678
679 // the only type of volume we support right now is disk partition
680 // so this structure is simple
681
682 *volExts = (VOLUME_DISK_EXTENTS) {
684 .Extents = {{
685 .DiskNumber = fdoExtension->DiskData.DeviceNumber,
686 .StartingOffset.QuadPart = partExt->StartingOffset,
687 .ExtentLength.QuadPart = partExt->PartitionLength
688 }}
689 };
690
691 PartMgrReleaseLayoutLock(fdoExtension);
692
694 Irp->IoStatus.Information = sizeof(*volExts);
695 break;
696 }
698 {
700 break;
701 }
703 {
704 PVOLUME_GET_GPT_ATTRIBUTES_INFORMATION gptAttrs = Irp->AssociatedIrp.SystemBuffer;
705 if (!VerifyIrpOutBufferSize(Irp, sizeof(*gptAttrs)))
706 {
708 break;
709 }
710
711 // not supported on anything other than GPT
712 if (fdoExtension->DiskData.PartitionStyle != PARTITION_STYLE_GPT)
713 {
715 break;
716 }
717
718 gptAttrs->GptAttributes = partExt->Gpt.Attributes;
719
721 Irp->IoStatus.Information = sizeof(*gptAttrs);
722 break;
723 }
724 // mountmgr stuff
726 {
727 PMOUNTDEV_NAME name = Irp->AssociatedIrp.SystemBuffer;
728
729 if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT)))
730 {
732 break;
733 }
734
735 name->NameLength = partExt->DeviceName.Length;
736
737 // return NameLength back
738 if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT) + name->NameLength))
739 {
740 Irp->IoStatus.Information = sizeof(USHORT);
742 break;
743 }
744
745 RtlCopyMemory(name->Name, partExt->DeviceName.Buffer, name->NameLength);
746
748 Irp->IoStatus.Information = sizeof(USHORT) + name->NameLength;
749 break;
750 }
752 {
753 PMOUNTDEV_UNIQUE_ID uniqueId = Irp->AssociatedIrp.SystemBuffer;
754
755 if (!partExt->VolumeInterfaceName.Buffer)
756 {
758 break;
759 }
760
761 if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT)))
762 {
764 break;
765 }
766
767 uniqueId->UniqueIdLength = partExt->VolumeInterfaceName.Length;
768
769 // return UniqueIdLength back
770 if (!VerifyIrpOutBufferSize(Irp, sizeof(USHORT) + uniqueId->UniqueIdLength))
771 {
772 Irp->IoStatus.Information = sizeof(USHORT);
774 break;
775 }
776
777 RtlCopyMemory(uniqueId->UniqueId,
779 uniqueId->UniqueIdLength);
780
782 Irp->IoStatus.Information = sizeof(USHORT) + uniqueId->UniqueIdLength;
783 break;
784 }
785 default:
787 }
788
789 Irp->IoStatus.Status = status;
791 return status;
792}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS FASTCALL IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: ntoskrnl.c:46
#define IOCTL_DISK_VERIFY
Definition: cdrw_usr.h:170
_In_ PIRP Irp
Definition: csq.h:116
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
NTSTATUS NTAPI IoSetPartitionInformationEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG PartitionNumber, IN PSET_PARTITION_INFORMATION_EX PartitionInfo)
Definition: fstubex.c:2347
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define ASSERT(a)
Definition: mode.c:44
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
struct _PARTITION_INFORMATION_EX PARTITION_INFORMATION_EX
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
#define IOCTL_MOUNTDEV_QUERY_UNIQUE_ID
Definition: imports.h:80
struct _PARTITION_INFORMATION_MBR PARTITION_INFORMATION_MBR
@ PARTITION_STYLE_GPT
Definition: imports.h:202
struct _PARTITION_INFORMATION_GPT PARTITION_INFORMATION_GPT
#define IOCTL_DISK_SET_PARTITION_INFO
Definition: ntdddisk.h:214
#define IOCTL_DISK_SET_PARTITION_INFO_EX
Definition: ntdddisk.h:217
struct _PARTITION_INFORMATION PARTITION_INFORMATION
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
#define IOCTL_DISK_UPDATE_PROPERTIES
Definition: ntdddisk.h:242
#define IOCTL_STORAGE_MEDIA_REMOVAL
Definition: ntddstor.h:104
#define IOCTL_VOLUME_GET_GPT_ATTRIBUTES
Definition: ntddvol.h:56
struct _VOLUME_DISK_EXTENTS VOLUME_DISK_EXTENTS
#define IOCTL_VOLUME_ONLINE
Definition: ntddvol.h:62
#define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
Definition: ntddvol.h:41
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
FORCEINLINE VOID PartMgrReleaseLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:187
FORCEINLINE VOID PartMgrAcquireLayoutLock(_In_ PFDO_EXTENSION FDOExtension)
Definition: partmgr.h:177
FORCEINLINE BOOLEAN VerifyIrpInBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:162
FORCEINLINE BOOLEAN VerifyIrpOutBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:147
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:1772
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
PDEVICE_OBJECT PhysicalDiskDO
Definition: partmgr.h:39
PDEVICE_OBJECT LowerDevice
Definition: partmgr.h:38
BOOLEAN LayoutValid
Definition: partmgr.h:42
struct _FDO_EXTENSION::@1314 DiskData
LARGE_INTEGER Length
Definition: imports.h:232
struct _IO_STACK_LOCATION::@1564::@1565 DeviceIoControl
union _IO_STACK_LOCATION::@1564 Parameters
USHORT UniqueIdLength
Definition: imports.h:138
UCHAR UniqueId[1]
Definition: imports.h:139
UNICODE_STRING VolumeInterfaceName
Definition: partmgr.h:99
BOOLEAN IsEnumerated
Definition: partmgr.h:78
LARGE_INTEGER StartingOffset
Definition: imports.h:221
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
PARTITION_INFORMATION_GPT Gpt
Definition: imports.h:227
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:656
ULONG NumberOfDiskExtents
Definition: ntddvol.h:119
Definition: name.c:39
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
@ BusRelations
Definition: iotypes.h:2152
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by PartMgrDeviceControl().

◆ PartitionHandleDeviceRelations()

static NTSTATUS PartitionHandleDeviceRelations ( _In_ PPARTITION_EXTENSION  PartExt,
_In_ PIRP  Irp 
)
static

Definition at line 247 of file partition.c.

250{
251 PAGED_CODE();
252
255
257 {
258 // Device relations has one entry built in to it's size.
259 PDEVICE_RELATIONS deviceRelations =
260 ExAllocatePoolZero(PagedPool, sizeof(DEVICE_RELATIONS), TAG_PARTMGR);
261
262 if (deviceRelations != NULL)
263 {
264 deviceRelations->Count = 1;
265 deviceRelations->Objects[0] = PartExt->DeviceObject;
266 ObReferenceObject(deviceRelations->Objects[0]);
267
268 Irp->IoStatus.Information = (ULONG_PTR)deviceRelations;
269 return STATUS_SUCCESS;
270 }
271 else
272 {
274 }
275 }
276 else
277 {
278 Irp->IoStatus.Information = 0;
279 return Irp->IoStatus.Status;
280 }
281}
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
#define PagedPool
Definition: env_spec_w32.h:308
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define TAG_PARTMGR
Definition: partmgr.h:23
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
struct _IO_STACK_LOCATION::@3978::@4003 QueryDeviceRelations
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
@ TargetDeviceRelation
Definition: iotypes.h:2156
enum _DEVICE_RELATION_TYPE DEVICE_RELATION_TYPE
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by PartitionHandlePnp().

◆ PartitionHandlePnp()

NTSTATUS PartitionHandlePnp ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 385 of file partition.c.

388{
389 PPARTITION_EXTENSION partExt = DeviceObject->DeviceExtension;
392
393 PAGED_CODE();
394
395 switch (ioStack->MinorFunction)
396 {
398 {
400 break;
401 }
403 {
405 break;
406 }
412 {
414 break;
415 }
417 {
419 break;
420 }
422 {
424 break;
425 }
426 case IRP_MN_QUERY_ID:
427 {
429 break;
430 }
432 {
434 break;
435 }
436 default:
437 {
438 Irp->IoStatus.Information = 0;
440 }
441 }
442
443 Irp->IoStatus.Status = status;
445 return status;
446}
#define TRUE
Definition: types.h:120
NTSTATUS PartitionHandleRemove(_In_ PPARTITION_EXTENSION PartExt, _In_ BOOLEAN FinalRemove)
Definition: partition.c:175
static NTSTATUS PartitionHandleQueryId(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:286
static NTSTATUS PartitionHandleDeviceRelations(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:247
static NTSTATUS PartitionHandleStartDevice(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:91
static NTSTATUS PartitionHandleQueryCapabilities(_In_ PPARTITION_EXTENSION PartExt, _In_ PIRP Irp)
Definition: partition.c:364
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define IRP_MN_CANCEL_STOP_DEVICE
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE
#define IRP_MN_QUERY_REMOVE_DEVICE

Referenced by PartMgrPnp().

◆ PartitionHandleQueryCapabilities()

static NTSTATUS PartitionHandleQueryCapabilities ( _In_ PPARTITION_EXTENSION  PartExt,
_In_ PIRP  Irp 
)
static

Definition at line 364 of file partition.c.

367{
369 PDEVICE_CAPABILITIES devCaps = ioStack->Parameters.DeviceCapabilities.Capabilities;
370
371 PAGED_CODE();
372 ASSERT(devCaps);
373
374 devCaps->SilentInstall = TRUE;
375 devCaps->RawDeviceOK = TRUE;
376 devCaps->NoDisplayInUI = TRUE;
377 devCaps->Address = PartExt->OnDiskNumber;
378 devCaps->UniqueID = FALSE;
379
380 return STATUS_SUCCESS;
381}
struct _IO_STACK_LOCATION::@3978::@4005 DeviceCapabilities
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965

Referenced by PartitionHandlePnp().

◆ PartitionHandleQueryId()

static NTSTATUS PartitionHandleQueryId ( _In_ PPARTITION_EXTENSION  PartExt,
_In_ PIRP  Irp 
)
static

Definition at line 286 of file partition.c.

289{
291 BUS_QUERY_ID_TYPE idType = ioStack->Parameters.QueryId.IdType;
292 UNICODE_STRING idString;
294
295 PAGED_CODE();
296
297 switch (idType)
298 {
299 case BusQueryDeviceID:
300 status = RtlCreateUnicodeString(&idString, L"STORAGE\\Partition")
302 break;
304 {
305 static WCHAR volumeID[] = L"STORAGE\\Volume\0";
306
307 idString.Buffer = ExAllocatePoolWithTag(PagedPool, sizeof(volumeID), TAG_PARTMGR);
308 RtlCopyMemory(idString.Buffer, volumeID, sizeof(volumeID));
309
311 break;
312 }
314 {
315 WCHAR string[64];
316 PFDO_EXTENSION fdoExtension = PartExt->LowerDevice->DeviceExtension;
317
318 PartMgrAcquireLayoutLock(fdoExtension);
319
320 if (fdoExtension->DiskData.PartitionStyle == PARTITION_STYLE_MBR)
321 {
322 swprintf(string, L"S%08lx_O%I64x_L%I64x",
323 fdoExtension->DiskData.Mbr.Signature,
324 PartExt->StartingOffset,
325 PartExt->PartitionLength);
326 }
327 else
328 {
329 swprintf(string,
330 L"S%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02xS_O%I64x_L%I64x",
331 fdoExtension->DiskData.Gpt.DiskId.Data1,
332 fdoExtension->DiskData.Gpt.DiskId.Data2,
333 fdoExtension->DiskData.Gpt.DiskId.Data3,
334 fdoExtension->DiskData.Gpt.DiskId.Data4[0],
335 fdoExtension->DiskData.Gpt.DiskId.Data4[1],
336 fdoExtension->DiskData.Gpt.DiskId.Data4[2],
337 fdoExtension->DiskData.Gpt.DiskId.Data4[3],
338 fdoExtension->DiskData.Gpt.DiskId.Data4[4],
339 fdoExtension->DiskData.Gpt.DiskId.Data4[5],
340 fdoExtension->DiskData.Gpt.DiskId.Data4[6],
341 fdoExtension->DiskData.Gpt.DiskId.Data4[7],
342 PartExt->StartingOffset,
343 PartExt->PartitionLength);
344 }
345
346 PartMgrReleaseLayoutLock(fdoExtension);
347
348 status = RtlCreateUnicodeString(&idString, string)
350 break;
351 }
352 default:
354 break;
355 }
356
357 Irp->IoStatus.Information = NT_SUCCESS(status) ? (ULONG_PTR) idString.Buffer : 0;
358 return status;
359}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct _IO_STACK_LOCATION::@3978::@4009 QueryId
enum _BUS_QUERY_ID_TYPE BUS_QUERY_ID_TYPE
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937

Referenced by PartitionHandlePnp().

◆ PartitionHandleRemove()

NTSTATUS PartitionHandleRemove ( _In_ PPARTITION_EXTENSION  PartExt,
_In_ BOOLEAN  FinalRemove 
)

Definition at line 175 of file partition.c.

178{
180
181 PAGED_CODE();
182
183 // remove the symbolic link
184 if (PartExt->SymlinkCreated)
185 {
186 WCHAR nameBuf[64];
187 UNICODE_STRING partitionSymlink;
188 PFDO_EXTENSION fdoExtension = PartExt->LowerDevice->DeviceExtension;
189
191 fdoExtension->DiskData.DeviceNumber, PartExt->DetectedNumber);
192
193 RtlInitUnicodeString(&partitionSymlink, nameBuf);
194
195 status = IoDeleteSymbolicLink(&partitionSymlink);
196
197 if (!NT_SUCCESS(status))
198 {
199 return status;
200 }
201 PartExt->SymlinkCreated = FALSE;
202
203 INFO("Symlink removed %wZ -> %wZ\n", &PartExt->DeviceName, &partitionSymlink);
204 }
205
206 // release device interfaces
207 if (PartExt->PartitionInterfaceName.Buffer)
208 {
209 status = IoSetDeviceInterfaceState(&PartExt->PartitionInterfaceName, FALSE);
210 if (!NT_SUCCESS(status))
211 {
212 return status;
213 }
214 RtlFreeUnicodeString(&PartExt->PartitionInterfaceName);
215 RtlInitUnicodeString(&PartExt->PartitionInterfaceName, NULL);
216 }
217
218 if (PartExt->VolumeInterfaceName.Buffer)
219 {
220 status = IoSetDeviceInterfaceState(&PartExt->VolumeInterfaceName, FALSE);
221 if (!NT_SUCCESS(status))
222 {
223 return status;
224 }
225 RtlFreeUnicodeString(&PartExt->VolumeInterfaceName);
226 RtlInitUnicodeString(&PartExt->VolumeInterfaceName, NULL);
227 }
228
229 if (FinalRemove)
230 {
231 ASSERT(PartExt->DeviceName.Buffer);
232 if (PartExt->DeviceName.Buffer)
233 {
234 INFO("Removed device %wZ\n", &PartExt->DeviceName);
235 RtlFreeUnicodeString(&PartExt->DeviceName);
236 }
237
238 IoDeleteDevice(PartExt->DeviceObject);
239 }
240
241 return STATUS_SUCCESS;
242}
static const WCHAR PartitionSymLinkFormat[]
Definition: partition.c:10
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311

Referenced by FdoHandleSurpriseRemoval(), PartitionHandlePnp(), and PartMgrUpdatePartitionDevices().

◆ PartitionHandleStartDevice()

static NTSTATUS PartitionHandleStartDevice ( _In_ PPARTITION_EXTENSION  PartExt,
_In_ PIRP  Irp 
)
static

Definition at line 91 of file partition.c.

94{
95 PAGED_CODE();
96
97 // first, create a symbolic link for our device
98 WCHAR nameBuf[64];
99 UNICODE_STRING partitionSymlink, interfaceName;
100 PFDO_EXTENSION fdoExtension = PartExt->LowerDevice->DeviceExtension;
101
102 // \\Device\\Harddisk%u\\Partition%u
104 fdoExtension->DiskData.DeviceNumber, PartExt->DetectedNumber);
105
106 if (!RtlCreateUnicodeString(&partitionSymlink, nameBuf))
107 {
109 }
110
111 NTSTATUS status = IoCreateSymbolicLink(&partitionSymlink, &PartExt->DeviceName);
112
113 if (!NT_SUCCESS(status))
114 {
115 return status;
116 }
117
118 PartExt->SymlinkCreated = TRUE;
119
120 TRACE("Symlink created %wZ -> %wZ\n", &PartExt->DeviceName, &partitionSymlink);
121
122 // our partition device will have two interfaces:
123 // GUID_DEVINTERFACE_PARTITION and GUID_DEVINTERFACE_VOLUME
124 // the former one is used to notify mountmgr about new device
125
126 status = IoRegisterDeviceInterface(PartExt->DeviceObject,
127 &GUID_DEVINTERFACE_PARTITION,
128 NULL,
129 &interfaceName);
130
131 if (!NT_SUCCESS(status))
132 {
133 return status;
134 }
135
136 PartExt->PartitionInterfaceName = interfaceName;
137 status = IoSetDeviceInterfaceState(&interfaceName, TRUE);
138
139 INFO("Partition interface %wZ\n", &interfaceName);
140
141 if (!NT_SUCCESS(status))
142 {
143 RtlFreeUnicodeString(&interfaceName);
144 RtlInitUnicodeString(&PartExt->PartitionInterfaceName, NULL);
145 return status;
146 }
147
148 status = IoRegisterDeviceInterface(PartExt->DeviceObject,
149 &GUID_DEVINTERFACE_VOLUME,
150 NULL,
151 &interfaceName);
152
153 if (!NT_SUCCESS(status))
154 {
155 return status;
156 }
157
158 PartExt->VolumeInterfaceName = interfaceName;
159 status = IoSetDeviceInterfaceState(&interfaceName, TRUE);
160
161 INFO("Volume interface %wZ\n", &interfaceName);
162
163 if (!NT_SUCCESS(status))
164 {
165 RtlFreeUnicodeString(&interfaceName);
166 RtlInitUnicodeString(&PartExt->VolumeInterfaceName, NULL);
167 return status;
168 }
169
170 return STATUS_SUCCESS;
171}
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by PartitionHandlePnp().

Variable Documentation

◆ PartitionSymLinkFormat

const WCHAR PartitionSymLinkFormat[] = L"\\Device\\Harddisk%u\\Partition%u"
static

Definition at line 10 of file partition.c.

Referenced by PartitionHandleRemove(), and PartitionHandleStartDevice().