MCPcopy Create free account
hub / github.com/bobranten/Ext4Fsd / Ext2SetPartitionType

Function Ext2SetPartitionType

Ext2Mgr/enumDisk.cpp:746–806  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

744
745
746BOOL
747Ext2SetPartitionType(
748 PEXT2_PARTITION Part,
749 BYTE Type
750 )
751{
752 BOOL rc = FALSE;
753 HANDLE Handle = NULL;
754 NT::NTSTATUS status;
755
756 UCHAR NumParts = 0;
757 PDRIVE_LAYOUT_INFORMATION_EXT Layout = NULL;
758
759 DWORD i;
760
761 status = Ext2Open(Part->Disk->Name, &Handle,
762 EXT2_DESIRED_ACCESS | GENERIC_WRITE);
763 if (!NT_SUCCESS(status)) {
764 goto errorout;
765 }
766
767 Layout = Part->Disk->Layout;
768
769 if (!Layout) {
770 goto errorout;
771 }
772
773 if (Layout->PartitionStyle != PARTITION_STYLE_MBR) {
774 goto errorout;
775 }
776
777 for (i=0; i < Layout->PartitionCount; i++) {
778
779 if ((Layout->PartitionEntry[i].StartingOffset.QuadPart ==
780 Part->Entry->StartingOffset.QuadPart) &&
781 (Layout->PartitionEntry[i].PartitionLength.QuadPart ==
782 Part->Entry->PartitionLength.QuadPart) &&
783 (Layout->PartitionEntry[i].PartitionNumber ==
784 Part->Entry->PartitionNumber) ) {
785
786 Layout->PartitionEntry[i].Mbr.PartitionType = Type;
787 Layout->PartitionEntry[i].RewritePartition = TRUE;
788
789 rc = TRUE;
790 break;
791 }
792 }
793
794 if (!rc) {
795 goto errorout;
796 }
797
798 status = Ext2SetDriveLayout(Handle, Layout);
799 rc = NT_SUCCESS(status);
800
801errorout:
802
803 Ext2Close(&Handle);

Callers 1

OnOKMethod · 0.85

Calls 3

Ext2OpenFunction · 0.85
Ext2SetDriveLayoutFunction · 0.85
Ext2CloseFunction · 0.70

Tested by

no test coverage detected