### ms-vds.idl
"""
RPC definitions for the following interfaces:
- IEnumVdsObject (v0.0): 118610b7-8d94-4030-b5b8-500889788e4e
- IVdsAdviseSink (v0.0): 8326cd1d-cf59-4936-b786-5efc08798e25
- IVdsAsync (v0.0): d5d23b6d-5a55-4492-9889-397a3c2d2dbc
- IVdsServiceLoader (v0.0): e0393303-90d4-4a97-ab71-e9b671ee2729
- IVdsService (v0.0): 0818a8ef-9ba9-40d8-a6f9-e22833cc771e
- IVdsServiceInitialization (v0.0): 4afc3636-db01-4052-80c3-03bbcb8d3c69
- IVdsServiceUninstallDisk (v0.0): B6B22DA8-F903-4be7-B492-C09D875AC9DA
- IVdsServiceHba (v0.0): 0ac13689-3134-47c6-a17c-4669216801be
- IVdsServiceIscsi (v0.0): 14fbe036-3ed7-4e10-90e9-a5ff991aff01
- IVdsServiceSAN (v0.0): FC5D23E8-A88B-41a5-8DE0-2D2F73C5A630
- IVdsServiceSw (v0.0): 15fc031c-0652-4306-b2c3-f558b8f837e2
- IVdsHbaPort (v0.0): 2abd757f-2851-4997-9a13-47d2a885d6ca
- IVdsIscsiInitiatorAdapter (v0.0): b07fedd4-1682-4440-9189-a39b55194dc5
- IVdsIscsiInitiatorPortal (v0.0): 38a0a9ab-7cc8-4693-ac07-1f28bd03c3da
- IVdsProvider (v0.0): 10c5e575-7984-4e81-a56b-431f5f92ae42
- IVdsSwProvider (v0.0): 9aa58360-ce33-4f92-b658-ed24b14425b8
- IVdsHwProvider (v0.0): d99bdaae-b13a-4178-9fdb-e27f16b4603e
- IVdsVdProvider (v0.0): b481498c-8354-45f9-84a0-0bdd2832a91f
- IVdsSubSystemImportTarget (v0.0): 83bfb87f-43fb-4903-baa6-127f01029eec
- IVdsPack (v0.0): 3b69d7f5-9d94-4648-91ca-79939ba263bf
- IVdsPack2 (v0.0): 13B50BFF-290A-47DD-8558-B7C58DB1A71A
- IVdsDisk (v0.0): 07e5c822-f00c-47a1-8fce-b244da56fd06
- IVdsDisk2 (v0.0): 40F73C8B-687D-4a13-8D96-3D7F2E683936
- IVdsDisk3 (v0.0): 8F4B2F5D-EC15-4357-992F-473EF10975B9
- IVdsAdvancedDisk (v0.0): 6e6f6b40-977c-4069-bddd-ac710059f8c0
- IVdsAdvancedDisk2 (v0.0): 9723f420-9355-42de-ab66-e31bb15beeac
- IVdsAdvancedDisk3 (v0.0): 3858C0D5-0F35-4BF5-9714-69874963BC36
- IVdsCreatePartitionEx (v0.0): 9882f547-cfc3-420b-9750-00dfbec50662
- IVdsDiskOnline (v0.0): 90681B1D-6A7F-48e8-9061-31B7AA125322
- IVdsDiskPartitionMF (v0.0): 538684e0-ba3d-4bc0-aca9-164aff85c2a9
- IVdsDiskPartitionMF2 (v0.0): 9CBE50CA-F2D2-4bf4-ACE1-96896B729625
- IVdsRemovable (v0.0): 0316560b-5db4-4ed9-bbb5-213436ddc0d9
- IVdsVolume (v0.0): 88306bb2-e71f-478c-86a2-79da200a0f11
- IVdsVolume2 (v0.0): 72AE6713-DCBB-4a03-B36B-371F6AC6B53D
- IVdsVolumeMF (v0.0): ee2d5ded-6236-4169-931d-b9778ce03dc6
- IVdsVolumeMF2 (v0.0): 4dbcee9a-6343-4651-b85f-5e75d74d983c
- IVdsVolumeMF3 (v0.0): 6788FAF9-214E-4b85-BA59-266953616E09
- IVdsVolumeShrink (v0.0): d68168c9-82a2-4f85-b6e9-74707c49a58f
- IVdsVolumeOnline (v0.0): 1BE2275A-B315-4f70-9E44-879B3A2A53F2
- IVdsVolumePlex (v0.0): 4daa0135-e1d1-40f1-aaa5-3cc1e53221c3
- IVdsVDisk (v0.0): 1e062b84-e5e6-4b4b-8a25-67b81e8f13e8
- IVdsOpenVDisk (v0.0): 75c8f324-f715-4fe3-a28e-f9011b61a4a1
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import PacketListField, StrFixedLenField, StrFixedLenFieldUtf16
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarPacketListField,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFieldListField,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRSignedShortField,
    NDRUnionField,
    register_com_interface,
)


class MInterfacePointer(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["abData"]
    fields_desc = [
        NDRIntField("ulCntData", None, size_of="abData"),
        NDRConfStrLenField(
            "abData", "", size_is=lambda pkt: pkt.ulCntData, conformant_in_struct=True
        ),
    ]


class Next_Request(NDRPacket):
    fields_desc = [NDRIntField("celt", 0)]


class Next_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "ppObjectArray",
            [],
            MInterfacePointer,
            size_is=lambda pkt: pkt.celt,
            length_is=lambda pkt: pkt.pcFetched,
            ptr_pack=True,
        ),
        NDRIntField("pcFetched", None, size_of="ppObjectArray"),
        NDRIntField("status", 0),
    ]


class Skip_Request(NDRPacket):
    fields_desc = [NDRIntField("celt", 0)]


class Skip_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Reset_Request(NDRPacket):
    fields_desc = []


class Reset_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Clone_Request(NDRPacket):
    fields_desc = []


class Clone_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IENUMVDSOBJECT_OPNUMS = {
    0: DceRpcOp(Next_Request, Next_Response),
    1: DceRpcOp(Skip_Request, Skip_Response),
    2: DceRpcOp(Reset_Request, Reset_Response),
    3: DceRpcOp(Clone_Request, Clone_Response),
}
register_com_interface(
    name="IEnumVdsObject",
    uuid=uuid.UUID("118610b7-8d94-4030-b5b8-500889788e4e"),
    opnums=IENUMVDSOBJECT_OPNUMS,
)


class VDS_NOTIFICATION_TARGET_TYPE(IntEnum):
    VDS_NTT_UNKNOWN = 0
    VDS_NTT_PACK = 10
    VDS_NTT_VOLUME = 11
    VDS_NTT_DISK = 13
    VDS_NTT_PARTITION = 60
    VDS_NTT_DRIVE_LETTER = 61
    VDS_NTT_FILE_SYSTEM = 62
    VDS_NTT_MOUNT_POINT = 63
    VDS_NTT_SERVICE = 200


class GUID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Data1", 0),
        NDRShortField("Data2", 0),
        NDRShortField("Data3", 0),
        StrFixedLenField("Data4", "", length=8),
    ]


class VDS_PACK_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("ulEvent", 0), NDRPacketField("packId", GUID(), GUID)]


class VDS_DISK_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("ulEvent", 0), NDRPacketField("diskId", GUID(), GUID)]


class VDS_VOLUME_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulEvent", 0),
        NDRPacketField("volumeId", GUID(), GUID),
        NDRPacketField("plexId", GUID(), GUID),
        NDRIntField("ulPercentCompleted", 0),
    ]


class VDS_PARTITION_NOTIFICATION(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("ulEvent", 0),
        NDRPacketField("diskId", GUID(), GUID),
        NDRLongField("ullOffset", 0),
    ]


class VDS_DRIVE_LETTER_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulEvent", 0),
        NDRShortField("wcLetter", 0),
        NDRPacketField("volumeId", GUID(), GUID),
    ]


class VDS_FILE_SYSTEM_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulEvent", 0),
        NDRPacketField("volumeId", GUID(), GUID),
        NDRIntField("dwPercentCompleted", 0),
    ]


class VDS_MOUNT_POINT_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("ulEvent", 0), NDRPacketField("volumeId", GUID(), GUID)]


class VDS_RECOVER_ACTION(IntEnum):
    VDS_RA_UNKNOWN = 0
    VDS_RA_REFRESH = 1
    VDS_RA_RESTART = 2


class VDS_SERVICE_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulEvent", 0),
        NDRInt3264EnumField("action", 0, VDS_RECOVER_ACTION),
    ]


class VDS_NOTIFICATION(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRInt3264EnumField("objectType", 0, VDS_NOTIFICATION_TARGET_TYPE),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "value", VDS_PACK_NOTIFICATION(), VDS_PACK_NOTIFICATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_PACK
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_PACK
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value", VDS_DISK_NOTIFICATION(), VDS_DISK_NOTIFICATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_DISK
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_DISK
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value", VDS_VOLUME_NOTIFICATION(), VDS_VOLUME_NOTIFICATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_VOLUME
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_VOLUME
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value",
                        VDS_PARTITION_NOTIFICATION(),
                        VDS_PARTITION_NOTIFICATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_PARTITION
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_PARTITION
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value",
                        VDS_DRIVE_LETTER_NOTIFICATION(),
                        VDS_DRIVE_LETTER_NOTIFICATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_DRIVE_LETTER
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_DRIVE_LETTER
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value",
                        VDS_FILE_SYSTEM_NOTIFICATION(),
                        VDS_FILE_SYSTEM_NOTIFICATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_FILE_SYSTEM
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_FILE_SYSTEM
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value",
                        VDS_MOUNT_POINT_NOTIFICATION(),
                        VDS_MOUNT_POINT_NOTIFICATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_MOUNT_POINT
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_MOUNT_POINT
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "value", VDS_SERVICE_NOTIFICATION(), VDS_SERVICE_NOTIFICATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "objectType", None)
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_SERVICE
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_NOTIFICATION_TARGET_TYPE.VDS_NTT_SERVICE
                        ),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class OnNotify_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("lNumberOfNotifications", None, size_of="pNotificationArray"),
        NDRConfPacketListField(
            "pNotificationArray",
            [],
            VDS_NOTIFICATION,
            size_is=lambda pkt: pkt.lNumberOfNotifications,
        ),
    ]


class OnNotify_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSADVISESINK_OPNUMS = {0: DceRpcOp(OnNotify_Request, OnNotify_Response)}
register_com_interface(
    name="IVdsAdviseSink",
    uuid=uuid.UUID("8326cd1d-cf59-4936-b786-5efc08798e25"),
    opnums=IVDSADVISESINK_OPNUMS,
)


class Cancel_Request(NDRPacket):
    fields_desc = []


class Cancel_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class VDS_ASYNC_OUTPUT_TYPE(IntEnum):
    VDS_ASYNCOUT_UNKNOWN = 0
    VDS_ASYNCOUT_CREATEVOLUME = 1
    VDS_ASYNCOUT_EXTENDVOLUME = 2
    VDS_ASYNCOUT_SHRINKVOLUME = 3
    VDS_ASYNCOUT_ADDVOLUMEPLEX = 4
    VDS_ASYNCOUT_BREAKVOLUMEPLEX = 5
    VDS_ASYNCOUT_REMOVEVOLUMEPLEX = 6
    VDS_ASYNCOUT_REPAIRVOLUMEPLEX = 7
    VDS_ASYNCOUT_RECOVERPACK = 8
    VDS_ASYNCOUT_REPLACEDISK = 9
    VDS_ASYNCOUT_CREATEPARTITION = 10
    VDS_ASYNCOUT_CLEAN = 11
    VDS_ASYNCOUT_CREATELUN = 50
    VDS_ASYNCOUT_FORMAT = 101
    VDS_ASYNCOUT_CREATE_VDISK = 200
    VDS_ASYNCOUT_SURFACE_VDISK = 201
    VDS_ASYNCOUT_COMPACT_VDISK = 202
    VDS_ASYNCOUT_MERGE_VDISK = 203
    VDS_ASYNCOUT_EXPAND_VDISK = 204


class cp_sub0(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRPacketField("volumeId", GUID(), GUID),
    ]


class cv_sub1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pVolumeUnk", MInterfacePointer(), MInterfacePointer),
            deferred=True,
        )
    ]


class bvp_sub2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pVolumeUnk", MInterfacePointer(), MInterfacePointer),
            deferred=True,
        )
    ]


class sv_sub3(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("ullReclaimedBytes", 0)]


class cvd_sub4(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pVDiskUnk", MInterfacePointer(), MInterfacePointer),
            deferred=True,
        )
    ]


class VDS_ASYNC_OUTPUT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_ASYNC_OUTPUT_TYPE),
        NDRUnionField(
            [
                (
                    NDRPacketField("value", cp_sub0(), cp_sub0),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_CREATEPARTITION
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_CREATEPARTITION
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", cv_sub1(), cv_sub1),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_CREATEVOLUME
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_CREATEVOLUME
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", bvp_sub2(), bvp_sub2),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_BREAKVOLUMEPLEX
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_BREAKVOLUMEPLEX
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", sv_sub3(), sv_sub3),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_SHRINKVOLUME
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_SHRINKVOLUME
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", cvd_sub4(), cvd_sub4),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_CREATE_VDISK
                        ),
                        (
                            lambda _, val: val.tag
                            == VDS_ASYNC_OUTPUT_TYPE.VDS_ASYNCOUT_CREATE_VDISK
                        ),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class Wait_Request(NDRPacket):
    fields_desc = []


class Wait_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pHrResult", 0),
        NDRPacketField("pAsyncOut", VDS_ASYNC_OUTPUT(), VDS_ASYNC_OUTPUT),
        NDRIntField("status", 0),
    ]


class QueryStatus_Request(NDRPacket):
    fields_desc = []


class QueryStatus_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pHrResult", 0),
        NDRIntField("pulPercentCompleted", 0),
        NDRIntField("status", 0),
    ]


IVDSASYNC_OPNUMS = {
    0: DceRpcOp(Cancel_Request, Cancel_Response),
    1: DceRpcOp(Wait_Request, Wait_Response),
    2: DceRpcOp(QueryStatus_Request, QueryStatus_Response),
}
register_com_interface(
    name="IVdsAsync",
    uuid=uuid.UUID("d5d23b6d-5a55-4492-9889-397a3c2d2dbc"),
    opnums=IVDSASYNC_OPNUMS,
)


class LoadService_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszMachineName", ""))
    ]


class LoadService_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppService", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSSERVICELOADER_OPNUMS = {0: DceRpcOp(LoadService_Request, LoadService_Response)}
register_com_interface(
    name="IVdsServiceLoader",
    uuid=uuid.UUID("e0393303-90d4-4a97-ab71-e9b671ee2729"),
    opnums=IVDSSERVICELOADER_OPNUMS,
)


class IsServiceReady_Request(NDRPacket):
    fields_desc = []


class IsServiceReady_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class WaitForServiceReady_Request(NDRPacket):
    fields_desc = []


class WaitForServiceReady_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class VDS_SERVICE_PROP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszVersion", ""), deferred=True
        ),
        NDRIntField("ulFlags", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pServiceProp", VDS_SERVICE_PROP(), VDS_SERVICE_PROP),
        NDRIntField("status", 0),
    ]


class QueryProviders_Request(NDRPacket):
    fields_desc = [NDRIntField("masks", 0)]


class QueryProviders_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class QueryUnallocatedDisks_Request(NDRPacket):
    fields_desc = []


class QueryUnallocatedDisks_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VDS_OBJECT_TYPE(IntEnum):
    VDS_OT_UNKNOWN = 0
    VDS_OT_PROVIDER = 1
    VDS_OT_PACK = 10
    VDS_OT_VOLUME = 11
    VDS_OT_VOLUME_PLEX = 12
    VDS_OT_DISK = 13
    VDS_OT_HBAPORT = 90
    VDS_OT_INIT_ADAPTER = 91
    VDS_OT_INIT_PORTAL = 92
    VDS_OT_ASYNC = 100
    VDS_OT_ENUM = 101
    VDS_OT_VDISK = 200
    VDS_OT_OPEN_VDISK = 201


class GetObject_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ObjectId", GUID(), GUID),
        NDRInt3264EnumField("type", 0, VDS_OBJECT_TYPE),
    ]


class GetObject_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppObjectUnk", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VDS_DRIVE_LETTER_PROP(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("wcLetter", 0),
        NDRPacketField("volumeId", GUID(), GUID),
        NDRIntField("ulFlags", 0),
        NDRSignedIntField("bUsed", 0),
    ]


class QueryDriveLetters_Request(NDRPacket):
    fields_desc = [NDRShortField("wcFirstLetter", 0), NDRIntField("count", 0)]


class QueryDriveLetters_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "pDriveLetterPropArray",
            [],
            VDS_DRIVE_LETTER_PROP,
            size_is=lambda pkt: pkt.count,
        ),
        NDRIntField("status", 0),
    ]


class VDS_FILE_SYSTEM_TYPE(IntEnum):
    VDS_FST_UNKNOWN = 0
    VDS_FST_RAW = 1
    VDS_FST_FAT = 2
    VDS_FST_FAT32 = 3
    VDS_FST_NTFS = 4
    VDS_FST_CDFS = 5
    VDS_FST_UDF = 6
    VDS_FST_EXFAT = 7
    VDS_FST_CSVFS = 8
    VDS_FST_REFS = 9


class VDS_FILE_SYSTEM_TYPE_PROP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_FILE_SYSTEM_TYPE),
        StrFixedLenFieldUtf16("wszName", "", length=8 * 2),
        NDRIntField("ulFlags", 0),
        NDRIntField("ulCompressionFlags", 0),
        NDRIntField("ulMaxLabelLength", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszIllegalLabelCharSet", ""), deferred=True
        ),
    ]


class QueryFileSystemTypes_Request(NDRPacket):
    fields_desc = []


class QueryFileSystemTypes_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppFileSystemTypeProps",
            [],
            VDS_FILE_SYSTEM_TYPE_PROP,
            size_is=lambda pkt: pkt.plNumberOfFileSystems,
            ptr_pack=True,
        ),
        NDRSignedIntField(
            "plNumberOfFileSystems", None, size_of="ppFileSystemTypeProps"
        ),
        NDRIntField("status", 0),
    ]


class Reenumerate_Request(NDRPacket):
    fields_desc = []


class Reenumerate_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Refresh_Request(NDRPacket):
    fields_desc = []


class Refresh_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class CleanupObsoleteMountPoints_Request(NDRPacket):
    fields_desc = []


class CleanupObsoleteMountPoints_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Advise_Request(NDRPacket):
    fields_desc = [NDRPacketField("pSink", MInterfacePointer(), MInterfacePointer)]


class Advise_Response(NDRPacket):
    fields_desc = [NDRIntField("pdwCookie", 0), NDRIntField("status", 0)]


class Unadvise_Request(NDRPacket):
    fields_desc = [NDRIntField("dwCookie", 0)]


class Unadvise_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Reboot_Request(NDRPacket):
    fields_desc = []


class Reboot_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class SetFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class SetFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class ClearFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class ClearFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSSERVICE_OPNUMS = {
    0: DceRpcOp(IsServiceReady_Request, IsServiceReady_Response),
    1: DceRpcOp(WaitForServiceReady_Request, WaitForServiceReady_Response),
    2: DceRpcOp(GetProperties_Request, GetProperties_Response),
    3: DceRpcOp(QueryProviders_Request, QueryProviders_Response),
    # 4: Opnum07NotUsedOnWire,
    5: DceRpcOp(QueryUnallocatedDisks_Request, QueryUnallocatedDisks_Response),
    6: DceRpcOp(GetObject_Request, GetObject_Response),
    7: DceRpcOp(QueryDriveLetters_Request, QueryDriveLetters_Response),
    8: DceRpcOp(QueryFileSystemTypes_Request, QueryFileSystemTypes_Response),
    9: DceRpcOp(Reenumerate_Request, Reenumerate_Response),
    10: DceRpcOp(Refresh_Request, Refresh_Response),
    11: DceRpcOp(
        CleanupObsoleteMountPoints_Request, CleanupObsoleteMountPoints_Response
    ),
    12: DceRpcOp(Advise_Request, Advise_Response),
    13: DceRpcOp(Unadvise_Request, Unadvise_Response),
    14: DceRpcOp(Reboot_Request, Reboot_Response),
    15: DceRpcOp(SetFlags_Request, SetFlags_Response),
    16: DceRpcOp(ClearFlags_Request, ClearFlags_Response),
}
register_com_interface(
    name="IVdsService",
    uuid=uuid.UUID("0818a8ef-9ba9-40d8-a6f9-e22833cc771e"),
    opnums=IVDSSERVICE_OPNUMS,
)


class Initialize_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszMachineName", ""))
    ]


class Initialize_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSSERVICEINITIALIZATION_OPNUMS = {
    0: DceRpcOp(Initialize_Request, Initialize_Response)
}
register_com_interface(
    name="IVdsServiceInitialization",
    uuid=uuid.UUID("4afc3636-db01-4052-80c3-03bbcb8d3c69"),
    opnums=IVDSSERVICEINITIALIZATION_OPNUMS,
)


class VDS_STORAGE_BUS_TYPE(IntEnum):
    VDSBusTypeUnknown = 0
    VDSBusTypeScsi = 1
    VDSBusTypeAtapi = 2
    VDSBusTypeAta = 3
    VDSBusType1394 = 4
    VDSBusTypeSsa = 5
    VDSBusTypeFibre = 6
    VDSBusTypeUsb = 7
    VDSBusTypeRAID = 8
    VDSBusTypeiScsi = 9
    VDSBusTypeSas = 10
    VDSBusTypeSata = 11
    VDSBusTypeSd = 12
    VDSBusTypeMmc = 13
    VDSBusTypeMax = 14
    VDSBusTypeVirtual = 14
    VDSBusTypeFileBackedVirtual = 15
    VDSBusTypeSpaces = 16
    VDSBusTypeMaxReserved = 127


class VDS_STORAGE_IDENTIFIER_CODE_SET(IntEnum):
    VDSStorageIdCodeSetReserved = 0
    VDSStorageIdCodeSetBinary = 1
    VDSStorageIdCodeSetAscii = 2
    VDSStorageIdCodeSetUtf8 = 3


class VDS_STORAGE_IDENTIFIER_TYPE(IntEnum):
    VDSStorageIdTypeVendorSpecific = 0
    VDSStorageIdTypeVendorId = 1
    VDSStorageIdTypeEUI64 = 2
    VDSStorageIdTypeFCPHName = 3
    VDSStorageIdTypePortRelative = 4
    VDSStorageIdTypeTargetPortGroup = 5
    VDSStorageIdTypeLogicalUnitGroup = 6
    VDSStorageIdTypeMD5LogicalUnitIdentifier = 7
    VDSStorageIdTypeScsiNameString = 8


class VDS_STORAGE_IDENTIFIER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("m_CodeSet", 0, VDS_STORAGE_IDENTIFIER_CODE_SET),
        NDRInt3264EnumField("m_Type", 0, VDS_STORAGE_IDENTIFIER_TYPE),
        NDRIntField("m_cbIdentifier", None, size_of="m_rgbIdentifier"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "m_rgbIdentifier", "", size_is=lambda pkt: pkt.m_cbIdentifier
            ),
            deferred=True,
        ),
    ]


class VDS_STORAGE_DEVICE_ID_DESCRIPTOR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("m_version", 0),
        NDRIntField("m_cIdentifiers", None, size_of="m_rgIdentifiers"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "m_rgIdentifiers",
                [],
                VDS_STORAGE_IDENTIFIER,
                size_is=lambda pkt: pkt.m_cIdentifiers,
            ),
            deferred=True,
        ),
    ]


class VDS_INTERCONNECT_ADDRESS_TYPE(IntEnum):
    VDS_IA_UNKNOWN = 0
    VDS_IA_FCFS = 1
    VDS_IA_FCPH = 2
    VDS_IA_FCPH3 = 3
    VDS_IA_MAC = 4
    VDS_IA_SCSI = 5


class VDS_INTERCONNECT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("m_addressType", 0, VDS_INTERCONNECT_ADDRESS_TYPE),
        NDRIntField("m_cbPort", None, size_of="m_pbPort"),
        NDRFullPointerField(
            NDRConfStrLenField("m_pbPort", "", size_is=lambda pkt: pkt.m_cbPort),
            deferred=True,
        ),
        NDRIntField("m_cbAddress", None, size_of="m_pbAddress"),
        NDRFullPointerField(
            NDRConfStrLenField("m_pbAddress", "", size_is=lambda pkt: pkt.m_cbAddress),
            deferred=True,
        ),
    ]


class VDS_LUN_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("m_version", 0),
        NDRSignedByteField("m_DeviceType", 0),
        NDRSignedByteField("m_DeviceTypeModifier", 0),
        NDRSignedIntField("m_bCommandQueuing", 0),
        NDRInt3264EnumField("m_BusType", 0, VDS_STORAGE_BUS_TYPE),
        NDRFullPointerField(NDRConfVarStrNullField("m_szVendorId", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullField("m_szProductId", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullField("m_szProductRevision", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullField("m_szSerialNumber", ""), deferred=True
        ),
        NDRPacketField("m_diskSignature", GUID(), GUID),
        NDRPacketField(
            "m_deviceIdDescriptor",
            VDS_STORAGE_DEVICE_ID_DESCRIPTOR(),
            VDS_STORAGE_DEVICE_ID_DESCRIPTOR,
        ),
        NDRIntField("m_cInterconnects", None, size_of="m_rgInterconnects"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "m_rgInterconnects",
                [],
                VDS_INTERCONNECT,
                size_is=lambda pkt: pkt.m_cInterconnects,
            ),
            deferred=True,
        ),
    ]


class GetDiskIdFromLunInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pLunInfo", VDS_LUN_INFORMATION(), VDS_LUN_INFORMATION)
    ]


class GetDiskIdFromLunInfo_Response(NDRPacket):
    fields_desc = [NDRPacketField("pDiskId", GUID(), GUID), NDRIntField("status", 0)]


class UninstallDisks_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "pDiskIdArray", [], GUID, size_is=lambda pkt: pkt.ulCount
        ),
        NDRIntField("ulCount", None, size_of="pDiskIdArray"),
        NDRIntField("bForce", 0),
    ]


class UninstallDisks_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pbReboot", 0),
        NDRConfFieldListField(
            "pResults", [], NDRSignedIntField("", 0), size_is=lambda pkt: pkt.ulCount
        ),
        NDRIntField("status", 0),
    ]


IVDSSERVICEUNINSTALLDISK_OPNUMS = {
    0: DceRpcOp(GetDiskIdFromLunInfo_Request, GetDiskIdFromLunInfo_Response),
    1: DceRpcOp(UninstallDisks_Request, UninstallDisks_Response),
}
register_com_interface(
    name="IVdsServiceUninstallDisk",
    uuid=uuid.UUID("B6B22DA8-F903-4be7-B492-C09D875AC9DA"),
    opnums=IVDSSERVICEUNINSTALLDISK_OPNUMS,
)


class QueryHbaPorts_Request(NDRPacket):
    fields_desc = []


class QueryHbaPorts_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSSERVICEHBA_OPNUMS = {0: DceRpcOp(QueryHbaPorts_Request, QueryHbaPorts_Response)}
register_com_interface(
    name="IVdsServiceHba",
    uuid=uuid.UUID("0ac13689-3134-47c6-a17c-4669216801be"),
    opnums=IVDSSERVICEHBA_OPNUMS,
)


class GetInitiatorName_Request(NDRPacket):
    fields_desc = []


class GetInitiatorName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppwszIscsiName", "")),
        NDRIntField("status", 0),
    ]


class QueryInitiatorAdapters_Request(NDRPacket):
    fields_desc = []


class QueryInitiatorAdapters_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VDS_ISCSI_SHARED_SECRET(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfStrLenField(
                "pSharedSecret", "", size_is=lambda pkt: pkt.ulSharedSecretSize
            ),
            deferred=True,
        ),
        NDRIntField("ulSharedSecretSize", None, size_of="pSharedSecret"),
    ]


class SetInitiatorSharedSecret_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "pInitiatorSharedSecret",
                VDS_ISCSI_SHARED_SECRET(),
                VDS_ISCSI_SHARED_SECRET,
            )
        ),
        NDRPacketField("targetId", GUID(), GUID),
    ]


class SetInitiatorSharedSecret_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSSERVICEISCSI_OPNUMS = {
    0: DceRpcOp(GetInitiatorName_Request, GetInitiatorName_Response),
    1: DceRpcOp(QueryInitiatorAdapters_Request, QueryInitiatorAdapters_Response),
    # 2: Opnum05NotUsedOnWire,
    # 3: Opnum06NotUsedOnWire,
    # 4: Opnum07NotUsedOnWire,
    5: DceRpcOp(SetInitiatorSharedSecret_Request, SetInitiatorSharedSecret_Response),
    # 6: Opnum09NotUsedOnWire
}
register_com_interface(
    name="IVdsServiceIscsi",
    uuid=uuid.UUID("14fbe036-3ed7-4e10-90e9-a5ff991aff01"),
    opnums=IVDSSERVICEISCSI_OPNUMS,
)


class VDS_SAN_POLICY(IntEnum):
    VDS_SP_UNKNOWN = 0
    VDS_SP_ONLINE = 1
    VDS_SP_OFFLINE_SHARED = 2
    VDS_SP_OFFLINE = 3
    VDS_SP_OFFLINE_INTERNAL = 4
    VDS_SP_MAX = 5


class GetSANPolicy_Request(NDRPacket):
    fields_desc = []


class GetSANPolicy_Response(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("pSanPolicy", 0, VDS_SAN_POLICY),
        NDRIntField("status", 0),
    ]


class SetSANPolicy_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("SanPolicy", 0, VDS_SAN_POLICY)]


class SetSANPolicy_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSSERVICESAN_OPNUMS = {
    0: DceRpcOp(GetSANPolicy_Request, GetSANPolicy_Response),
    1: DceRpcOp(SetSANPolicy_Request, SetSANPolicy_Response),
}
register_com_interface(
    name="IVdsServiceSAN",
    uuid=uuid.UUID("FC5D23E8-A88B-41a5-8DE0-2D2F73C5A630"),
    opnums=IVDSSERVICESAN_OPNUMS,
)


class GetDiskObject_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("pwszDeviceID", "")]


class GetDiskObject_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppDiskUnk", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSSERVICESW_OPNUMS = {0: DceRpcOp(GetDiskObject_Request, GetDiskObject_Response)}
register_com_interface(
    name="IVdsServiceSw",
    uuid=uuid.UUID("15fc031c-0652-4306-b2c3-f558b8f837e2"),
    opnums=IVDSSERVICESW_OPNUMS,
)


class VDS_WWN(NDRPacket):
    fields_desc = [StrFixedLenField("rguchWwn", "", length=8)]


class VDS_HBAPORT_TYPE(IntEnum):
    VDS_HPT_UNKNOWN = 1
    VDS_HPT_OTHER = 2
    VDS_HPT_NOTPRESENT = 3
    VDS_HPT_NPORT = 5
    VDS_HPT_NLPORT = 6
    VDS_HPT_FLPORT = 7
    VDS_HPT_FPORT = 8
    VDS_HPT_EPORT = 9
    VDS_HPT_GPORT = 10
    VDS_HPT_LPORT = 20
    VDS_HPT_PTP = 21


class VDS_HBAPORT_STATUS(IntEnum):
    VDS_HPS_UNKNOWN = 1
    VDS_HPS_ONLINE = 2
    VDS_HPS_OFFLINE = 3
    VDS_HPS_BYPASSED = 4
    VDS_HPS_DIAGNOSTICS = 5
    VDS_HPS_LINKDOWN = 6
    VDS_HPS_ERROR = 7
    VDS_HPS_LOOPBACK = 8


class VDS_HBAPORT_PROP(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRPacketField("wwnNode", VDS_WWN(), VDS_WWN),
        NDRPacketField("wwnPort", VDS_WWN(), VDS_WWN),
        NDRInt3264EnumField("type", 0, VDS_HBAPORT_TYPE),
        NDRInt3264EnumField("status", 0, VDS_HBAPORT_STATUS),
        NDRIntField("ulPortSpeed", 0),
        NDRIntField("ulSupportedPortSpeed", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pHbaPortProp", VDS_HBAPORT_PROP(), VDS_HBAPORT_PROP),
        NDRIntField("status", 0),
    ]


class VDS_PATH_STATUS(IntEnum):
    VDS_MPS_UNKNOWN = 0
    VDS_MPS_ONLINE = 1
    VDS_MPS_FAILED = 5
    VDS_MPS_STANDBY = 7


class SetAllPathStatuses_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("status", 0, VDS_PATH_STATUS)]


class SetAllPathStatuses_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSHBAPORT_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(SetAllPathStatuses_Request, SetAllPathStatuses_Response),
}
register_com_interface(
    name="IVdsHbaPort",
    uuid=uuid.UUID("2abd757f-2851-4997-9a13-47d2a885d6ca"),
    opnums=IVDSHBAPORT_OPNUMS,
)


class VDS_ISCSI_INITIATOR_ADAPTER_PROP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "pInitiatorAdapterProp",
            VDS_ISCSI_INITIATOR_ADAPTER_PROP(),
            VDS_ISCSI_INITIATOR_ADAPTER_PROP,
        ),
        NDRIntField("status", 0),
    ]


class QueryInitiatorPortals_Request(NDRPacket):
    fields_desc = []


class QueryInitiatorPortals_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSISCSIINITIATORADAPTER_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(QueryInitiatorPortals_Request, QueryInitiatorPortals_Response),
    # 2: Opnum05NotUsedOnWire,
    # 3: Opnum06NotUsedOnWire
}
register_com_interface(
    name="IVdsIscsiInitiatorAdapter",
    uuid=uuid.UUID("b07fedd4-1682-4440-9189-a39b55194dc5"),
    opnums=IVDSISCSIINITIATORADAPTER_OPNUMS,
)


class VDS_IPADDRESS_TYPE(IntEnum):
    VDS_IPT_TEXT = 0
    VDS_IPT_IPV4 = 1
    VDS_IPT_IPV6 = 2
    VDS_IPT_EMPTY = 3


class VDS_IPADDRESS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_IPADDRESS_TYPE),
        NDRIntField("ipv4Address", 0),
        StrFixedLenField("ipv6Address", "", length=16),
        NDRIntField("ulIpv6FlowInfo", 0),
        NDRIntField("ulIpv6ScopeId", 0),
        StrFixedLenFieldUtf16("wszTextAddress", "", length=(256 + 1) * 2),
        NDRIntField("ulPort", 0),
    ]


class VDS_ISCSI_INITIATOR_PORTAL_PROP(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRPacketField("address", VDS_IPADDRESS(), VDS_IPADDRESS),
        NDRIntField("ulPortIndex", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "pInitiatorPortalProp",
            VDS_ISCSI_INITIATOR_PORTAL_PROP(),
            VDS_ISCSI_INITIATOR_PORTAL_PROP,
        ),
        NDRIntField("status", 0),
    ]


class GetInitiatorAdapter_Request(NDRPacket):
    fields_desc = []


class GetInitiatorAdapter_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppInitiatorAdapter", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSISCSIINITIATORPORTAL_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(GetInitiatorAdapter_Request, GetInitiatorAdapter_Response),
    # 2: Opnum05NotUsedOnWire,
    # 3: Opnum06NotUsedOnWire,
    # 4: Opnum07NotUsedOnWire
}
register_com_interface(
    name="IVdsIscsiInitiatorPortal",
    uuid=uuid.UUID("38a0a9ab-7cc8-4693-ac07-1f28bd03c3da"),
    opnums=IVDSISCSIINITIATORPORTAL_OPNUMS,
)


class VDS_PROVIDER_TYPE(IntEnum):
    VDS_PT_UNKNOWN = 0
    VDS_PT_SOFTWARE = 1
    VDS_PT_HARDWARE = 2
    VDS_PT_VIRTUALDISK = 3
    VDS_PT_MAX = 4


class VDS_PROVIDER_PROP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
        NDRPacketField("guidVersionId", GUID(), GUID),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszVersion", ""), deferred=True
        ),
        NDRInt3264EnumField("type", 0, VDS_PROVIDER_TYPE),
        NDRIntField("ulFlags", 0),
        NDRIntField("ulStripeSizeFlags", 0),
        NDRSignedShortField("sRebuildPriority", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pProviderProp", VDS_PROVIDER_PROP(), VDS_PROVIDER_PROP),
        NDRIntField("status", 0),
    ]


IVDSPROVIDER_OPNUMS = {0: DceRpcOp(GetProperties_Request, GetProperties_Response)}
register_com_interface(
    name="IVdsProvider",
    uuid=uuid.UUID("10c5e575-7984-4e81-a56b-431f5f92ae42"),
    opnums=IVDSPROVIDER_OPNUMS,
)


class QueryPacks_Request(NDRPacket):
    fields_desc = []


class QueryPacks_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class CreatePack_Request(NDRPacket):
    fields_desc = []


class CreatePack_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppPack", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSSWPROVIDER_OPNUMS = {
    0: DceRpcOp(QueryPacks_Request, QueryPacks_Response),
    1: DceRpcOp(CreatePack_Request, CreatePack_Response),
}
register_com_interface(
    name="IVdsSwProvider",
    uuid=uuid.UUID("9aa58360-ce33-4f92-b658-ed24b14425b8"),
    opnums=IVDSSWPROVIDER_OPNUMS,
)


class QuerySubSystems_Request(NDRPacket):
    fields_desc = []


class QuerySubSystems_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSHWPROVIDER_OPNUMS = {
    0: DceRpcOp(QuerySubSystems_Request, QuerySubSystems_Response),
    # 1: Opnum04NotUsedOnWire,
    # 2: Opnum05NotUsedOnWire
}
register_com_interface(
    name="IVdsHwProvider",
    uuid=uuid.UUID("d99bdaae-b13a-4178-9fdb-e27f16b4603e"),
    opnums=IVDSHWPROVIDER_OPNUMS,
)


class QueryVDisks_Request(NDRPacket):
    fields_desc = []


class QueryVDisks_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VIRTUAL_STORAGE_TYPE(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("DeviceId", 0), NDRPacketField("VendorId", GUID(), GUID)]


class CREATE_VIRTUAL_DISK_FLAG(IntEnum):
    CREATE_VIRTUAL_DISK_FLAG_NONE = 0
    CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION = 1


class PVDS_CREATE_VDISK_PARAMETERS(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("UniqueId", GUID(), GUID),
        NDRLongField("MaximumSize", 0),
        NDRIntField("BlockSizeInBytes", 0),
        NDRIntField("SectorSizeInBytes", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pParentPath", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pSourcePath", ""), deferred=True
        ),
    ]


class CreateVDisk_Request(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "VirtualDeviceType", VIRTUAL_STORAGE_TYPE(), VIRTUAL_STORAGE_TYPE
        ),
        NDRConfVarStrNullFieldUtf16("pPath", ""),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pStringSecurityDescriptor", "")
        ),
        NDRInt3264EnumField("Flags", 0, CREATE_VIRTUAL_DISK_FLAG),
        NDRIntField("ProviderSpecificFlags", 0),
        NDRIntField("Reserved", 0),
        NDRPacketField(
            "pCreateDiskParameters",
            PVDS_CREATE_VDISK_PARAMETERS(),
            PVDS_CREATE_VDISK_PARAMETERS,
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


class CreateVDisk_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRIntField("status", 0),
    ]


class AddVDisk_Request(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "VirtualDeviceType", VIRTUAL_STORAGE_TYPE(), VIRTUAL_STORAGE_TYPE
        ),
        NDRConfVarStrNullFieldUtf16("pPath", ""),
    ]


class AddVDisk_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppVDisk", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class GetDiskFromVDisk_Request(NDRPacket):
    fields_desc = [NDRPacketField("pVDisk", MInterfacePointer(), MInterfacePointer)]


class GetDiskFromVDisk_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppDisk", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class GetVDiskFromDisk_Request(NDRPacket):
    fields_desc = [NDRPacketField("pDisk", MInterfacePointer(), MInterfacePointer)]


class GetVDiskFromDisk_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppVDisk", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSVDPROVIDER_OPNUMS = {
    0: DceRpcOp(QueryVDisks_Request, QueryVDisks_Response),
    1: DceRpcOp(CreateVDisk_Request, CreateVDisk_Response),
    2: DceRpcOp(AddVDisk_Request, AddVDisk_Response),
    3: DceRpcOp(GetDiskFromVDisk_Request, GetDiskFromVDisk_Response),
    4: DceRpcOp(GetVDiskFromDisk_Request, GetVDiskFromDisk_Response),
}
register_com_interface(
    name="IVdsVdProvider",
    uuid=uuid.UUID("b481498c-8354-45f9-84a0-0bdd2832a91f"),
    opnums=IVDSVDPROVIDER_OPNUMS,
)


class GetImportTarget_Request(NDRPacket):
    fields_desc = []


class GetImportTarget_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppwszIscsiName", "")),
        NDRIntField("status", 0),
    ]


class SetImportTarget_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszIscsiName", ""))
    ]


class SetImportTarget_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSSUBSYSTEMIMPORTTARGET_OPNUMS = {
    0: DceRpcOp(GetImportTarget_Request, GetImportTarget_Response),
    1: DceRpcOp(SetImportTarget_Request, SetImportTarget_Response),
}
register_com_interface(
    name="IVdsSubSystemImportTarget",
    uuid=uuid.UUID("83bfb87f-43fb-4903-baa6-127f01029eec"),
    opnums=IVDSSUBSYSTEMIMPORTTARGET_OPNUMS,
)


class VDS_PACK_STATUS(IntEnum):
    VDS_PS_UNKNOWN = 0
    VDS_PS_ONLINE = 1
    VDS_PS_OFFLINE = 4


class VDS_PACK_PROP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
        NDRInt3264EnumField("status", 0, VDS_PACK_STATUS),
        NDRIntField("ulFlags", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pPackProp", VDS_PACK_PROP(), VDS_PACK_PROP),
        NDRIntField("status", 0),
    ]


class GetProvider_Request(NDRPacket):
    fields_desc = []


class GetProvider_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppProvider", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class QueryVolumes_Request(NDRPacket):
    fields_desc = []


class QueryVolumes_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class QueryDisks_Request(NDRPacket):
    fields_desc = []


class QueryDisks_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VDS_VOLUME_TYPE(IntEnum):
    VDS_VT_UNKNOWN = 0
    VDS_VT_SIMPLE = 10
    VDS_VT_SPAN = 11
    VDS_VT_STRIPE = 12
    VDS_VT_MIRROR = 13
    VDS_VT_PARITY = 14


class VDS_INPUT_DISK(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("diskId", GUID(), GUID),
        NDRLongField("ullSize", 0),
        NDRPacketField("plexId", GUID(), GUID),
        NDRIntField("memberIdx", 0),
    ]


class CreateVolume_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_VOLUME_TYPE),
        NDRConfPacketListField(
            "pInputDiskArray",
            [],
            VDS_INPUT_DISK,
            size_is=lambda pkt: pkt.lNumberOfDisks,
        ),
        NDRSignedIntField("lNumberOfDisks", None, size_of="pInputDiskArray"),
        NDRIntField("ulStripeSize", 0),
    ]


class CreateVolume_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VDS_PARTITION_STYLE(IntEnum):
    VDS_PST_UNKNOWN = 0
    VDS_PST_MBR = 1
    VDS_PST_GPT = 2


class AddDisk_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("DiskId", GUID(), GUID),
        NDRInt3264EnumField("PartitionStyle", 0, VDS_PARTITION_STYLE),
        NDRSignedIntField("bAsHotSpare", 0),
    ]


class AddDisk_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class MigrateDisks_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "pDiskArray", [], GUID, size_is=lambda pkt: pkt.lNumberOfDisks
        ),
        NDRSignedIntField("lNumberOfDisks", None, size_of="pDiskArray"),
        NDRPacketField("TargetPack", GUID(), GUID),
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bQueryOnly", 0),
    ]


class MigrateDisks_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "pResults",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.lNumberOfDisks,
        ),
        NDRSignedIntField("pbRebootNeeded", 0),
        NDRIntField("status", 0),
    ]


class RemoveMissingDisk_Request(NDRPacket):
    fields_desc = [NDRPacketField("DiskId", GUID(), GUID)]


class RemoveMissingDisk_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Recover_Request(NDRPacket):
    fields_desc = []


class Recover_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSPACK_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(GetProvider_Request, GetProvider_Response),
    2: DceRpcOp(QueryVolumes_Request, QueryVolumes_Response),
    3: DceRpcOp(QueryDisks_Request, QueryDisks_Response),
    4: DceRpcOp(CreateVolume_Request, CreateVolume_Response),
    5: DceRpcOp(AddDisk_Request, AddDisk_Response),
    6: DceRpcOp(MigrateDisks_Request, MigrateDisks_Response),
    # 7: Opnum10NotUsedOnWire,
    8: DceRpcOp(RemoveMissingDisk_Request, RemoveMissingDisk_Response),
    9: DceRpcOp(Recover_Request, Recover_Response),
}
register_com_interface(
    name="IVdsPack",
    uuid=uuid.UUID("3b69d7f5-9d94-4648-91ca-79939ba263bf"),
    opnums=IVDSPACK_OPNUMS,
)


class CreateVolume2_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_VOLUME_TYPE),
        NDRConfPacketListField(
            "pInputDiskArray",
            [],
            VDS_INPUT_DISK,
            size_is=lambda pkt: pkt.lNumberOfDisks,
        ),
        NDRSignedIntField("lNumberOfDisks", None, size_of="pInputDiskArray"),
        NDRIntField("ulStripeSize", 0),
        NDRIntField("ulAlign", 0),
    ]


class CreateVolume2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSPACK2_OPNUMS = {0: DceRpcOp(CreateVolume2_Request, CreateVolume2_Response)}
register_com_interface(
    name="IVdsPack2",
    uuid=uuid.UUID("13B50BFF-290A-47DD-8558-B7C58DB1A71A"),
    opnums=IVDSPACK2_OPNUMS,
)


class VDS_DISK_STATUS(IntEnum):
    VDS_DS_UNKNOWN = 0
    VDS_DS_ONLINE = 1
    VDS_DS_NOT_READY = 2
    VDS_DS_NO_MEDIA = 3
    VDS_DS_OFFLINE = 4
    VDS_DS_FAILED = 5
    VDS_DS_MISSING = 6


class VDS_LUN_RESERVE_MODE(IntEnum):
    VDS_LRM_NONE = 0
    VDS_LRM_EXCLUSIVE_RW = 1
    VDS_LRM_EXCLUSIVE_RO = 2
    VDS_LRM_SHARED_RO = 3
    VDS_LRM_SHARED_RW = 4


class VDS_HEALTH(IntEnum):
    VDS_H_UNKNOWN = 0
    VDS_H_HEALTHY = 1
    VDS_H_REBUILDING = 2
    VDS_H_STALE = 3
    VDS_H_FAILING = 4
    VDS_H_FAILING_REDUNDANCY = 5
    VDS_H_FAILED_REDUNDANCY = 6
    VDS_H_FAILED_REDUNDANCY_FAILING = 7
    VDS_H_FAILED = 8


class VDS_DISK_PROP(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRInt3264EnumField("status", 0, VDS_DISK_STATUS),
        NDRInt3264EnumField("ReserveMode", 0, VDS_LUN_RESERVE_MODE),
        NDRInt3264EnumField("health", 0, VDS_HEALTH),
        NDRIntField("dwDeviceType", 0),
        NDRIntField("dwMediaType", 0),
        NDRLongField("ullSize", 0),
        NDRIntField("ulBytesPerSector", 0),
        NDRIntField("ulSectorsPerTrack", 0),
        NDRIntField("ulTracksPerCylinder", 0),
        NDRIntField("ulFlags", 0),
        NDRInt3264EnumField("BusType", 0, VDS_STORAGE_BUS_TYPE),
        NDRInt3264EnumField("PartitionStyle", 0, VDS_PARTITION_STYLE),
        NDRUnionField(
            [
                (
                    NDRIntField("value", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 4),
            switch_fmt=("H", "I"),
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszDiskAddress", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszFriendlyName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszAdaptorName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszDevicePath", ""), deferred=True
        ),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pDiskProperties", VDS_DISK_PROP(), VDS_DISK_PROP),
        NDRIntField("status", 0),
    ]


class GetPack_Request(NDRPacket):
    fields_desc = []


class GetPack_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppPack", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class GetIdentificationData_Request(NDRPacket):
    fields_desc = []


class GetIdentificationData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pLunInfo", VDS_LUN_INFORMATION(), VDS_LUN_INFORMATION),
        NDRIntField("status", 0),
    ]


class VDS_DISK_EXTENT_TYPE(IntEnum):
    VDS_DET_UNKNOWN = 0
    VDS_DET_FREE = 1
    VDS_DET_DATA = 2
    VDS_DET_OEM = 3
    VDS_DET_ESP = 4
    VDS_DET_MSR = 5
    VDS_DET_LDM = 6
    VDS_DET_UNUSABLE = 32767


class VDS_DISK_EXTENT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("diskId", GUID(), GUID),
        NDRInt3264EnumField("type", 0, VDS_DISK_EXTENT_TYPE),
        NDRLongField("ullOffset", 0),
        NDRLongField("ullSize", 0),
        NDRPacketField("volumeId", GUID(), GUID),
        NDRPacketField("plexId", GUID(), GUID),
        NDRIntField("memberIdx", 0),
    ]


class QueryExtents_Request(NDRPacket):
    fields_desc = []


class QueryExtents_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppExtentArray",
            [],
            VDS_DISK_EXTENT,
            size_is=lambda pkt: pkt.plNumberOfExtents,
            ptr_pack=True,
        ),
        NDRSignedIntField("plNumberOfExtents", None, size_of="ppExtentArray"),
        NDRIntField("status", 0),
    ]


class ConvertStyle_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("NewStyle", 0, VDS_PARTITION_STYLE)]


class ConvertStyle_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class SetFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class SetFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class ClearFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class ClearFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSDISK_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(GetPack_Request, GetPack_Response),
    2: DceRpcOp(GetIdentificationData_Request, GetIdentificationData_Response),
    3: DceRpcOp(QueryExtents_Request, QueryExtents_Response),
    4: DceRpcOp(ConvertStyle_Request, ConvertStyle_Response),
    5: DceRpcOp(SetFlags_Request, SetFlags_Response),
    6: DceRpcOp(ClearFlags_Request, ClearFlags_Response),
}
register_com_interface(
    name="IVdsDisk",
    uuid=uuid.UUID("07e5c822-f00c-47a1-8fce-b244da56fd06"),
    opnums=IVDSDISK_OPNUMS,
)


class SetSANMode_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("bEnable", 0)]


class SetSANMode_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSDISK2_OPNUMS = {0: DceRpcOp(SetSANMode_Request, SetSANMode_Response)}
register_com_interface(
    name="IVdsDisk2",
    uuid=uuid.UUID("40F73C8B-687D-4a13-8D96-3D7F2E683936"),
    opnums=IVDSDISK2_OPNUMS,
)


class VDS_DISK_PROP2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRInt3264EnumField("status", 0, VDS_DISK_STATUS),
        NDRInt3264EnumField("ReserveMode", 0, VDS_LUN_RESERVE_MODE),
        NDRInt3264EnumField("health", 0, VDS_HEALTH),
        NDRIntField("dwDeviceType", 0),
        NDRIntField("dwMediaType", 0),
        NDRLongField("ullSize", 0),
        NDRIntField("ulBytesPerSector", 0),
        NDRIntField("ulSectorsPerTrack", 0),
        NDRIntField("ulTracksPerCylinder", 0),
        NDRIntField("ulFlags", 0),
        NDRInt3264EnumField("BusType", 0, VDS_STORAGE_BUS_TYPE),
        NDRInt3264EnumField("PartitionStyle", 0, VDS_PARTITION_STYLE),
        NDRUnionField(
            [
                (
                    NDRIntField("value", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 4),
            switch_fmt=("H", "I"),
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszDiskAddress", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszFriendlyName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszAdaptorName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszDevicePath", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszLocationPath", ""), deferred=True
        ),
    ]


class GetProperties2_Request(NDRPacket):
    fields_desc = []


class GetProperties2_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pDiskProperties", VDS_DISK_PROP2(), VDS_DISK_PROP2),
        NDRIntField("status", 0),
    ]


class VDS_DISK_FREE_EXTENT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("diskId", GUID(), GUID),
        NDRLongField("ullOffset", 0),
        NDRLongField("ullSize", 0),
    ]


class QueryFreeExtents_Request(NDRPacket):
    fields_desc = [NDRIntField("ulAlign", 0)]


class QueryFreeExtents_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppFreeExtentArray",
            [],
            VDS_DISK_FREE_EXTENT,
            size_is=lambda pkt: pkt.plNumberOfFreeExtents,
            ptr_pack=True,
        ),
        NDRSignedIntField("plNumberOfFreeExtents", None, size_of="ppFreeExtentArray"),
        NDRIntField("status", 0),
    ]


IVDSDISK3_OPNUMS = {
    0: DceRpcOp(GetProperties2_Request, GetProperties2_Response),
    1: DceRpcOp(QueryFreeExtents_Request, QueryFreeExtents_Response),
}
register_com_interface(
    name="IVdsDisk3",
    uuid=uuid.UUID("8F4B2F5D-EC15-4357-992F-473EF10975B9"),
    opnums=IVDSDISK3_OPNUMS,
)


class VDS_PARTITION_INFO_MBR(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRSignedByteField("partitionType", 0),
        NDRIntField("bootIndicator", 0),
        NDRIntField("recognizedPartition", 0),
        NDRIntField("hiddenSectors", 0),
    ]


class VDS_PARTITION_INFO_GPT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("partitionType", GUID(), GUID),
        NDRPacketField("partitionId", GUID(), GUID),
        NDRLongField("attributes", 0),
        StrFixedLenFieldUtf16("name", "", length=36 * 2),
    ]


class VDS_PARTITION_PROP(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRInt3264EnumField("PartitionStyle", 0, VDS_PARTITION_STYLE),
        NDRIntField("ulFlags", 0),
        NDRIntField("ulPartitionNumber", 0),
        NDRLongField("ullOffset", 0),
        NDRLongField("ullSize", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "value", VDS_PARTITION_INFO_MBR(), VDS_PARTITION_INFO_MBR
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField(
                        "value", VDS_PARTITION_INFO_GPT(), VDS_PARTITION_INFO_GPT
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class GetPartitionProperties_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0)]


class GetPartitionProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pPartitionProp", VDS_PARTITION_PROP(), VDS_PARTITION_PROP),
        NDRIntField("status", 0),
    ]


class QueryPartitions_Request(NDRPacket):
    fields_desc = []


class QueryPartitions_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppPartitionPropArray",
            [],
            VDS_PARTITION_PROP,
            size_is=lambda pkt: pkt.plNumberOfPartitions,
            ptr_pack=True,
        ),
        NDRSignedIntField("plNumberOfPartitions", None, size_of="ppPartitionPropArray"),
        NDRIntField("status", 0),
    ]


class MbrPartInfo_sub0(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRSignedByteField("partitionType", 0),
        NDRIntField("bootIndicator", 0),
    ]


class GptPartInfo_sub1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("partitionType", GUID(), GUID),
        NDRPacketField("partitionId", GUID(), GUID),
        NDRLongField("attributes", 0),
        StrFixedLenFieldUtf16("name", "", length=24 * 2),
    ]


class CREATE_PARTITION_PARAMETERS(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRInt3264EnumField("style", 0, VDS_PARTITION_STYLE),
        NDRUnionField(
            [
                (
                    NDRPacketField("value", MbrPartInfo_sub0(), MbrPartInfo_sub0),
                    (
                        (
                            lambda pkt: getattr(pkt, "style", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField("value", GptPartInfo_sub1(), GptPartInfo_sub1),
                    (
                        (
                            lambda pkt: getattr(pkt, "style", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class CreatePartition_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRLongField("ullSize", 0),
        NDRPacketField(
            "para", CREATE_PARTITION_PARAMETERS(), CREATE_PARTITION_PARAMETERS
        ),
    ]


class CreatePartition_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class DeletePartition_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bForceProtected", 0),
    ]


class DeletePartition_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class MbrPartInfo_sub0(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("bootIndicator", 0)]


class GptPartInfo_sub1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("attributes", 0)]


class CHANGE_ATTRIBUTES_PARAMETERS(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRInt3264EnumField("style", 0, VDS_PARTITION_STYLE),
        NDRUnionField(
            [
                (
                    NDRPacketField("value", MbrPartInfo_sub0(), MbrPartInfo_sub0),
                    (
                        (
                            lambda pkt: getattr(pkt, "style", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField("value", GptPartInfo_sub1(), GptPartInfo_sub1),
                    (
                        (
                            lambda pkt: getattr(pkt, "style", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class ChangeAttributes_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRPacketField(
            "para", CHANGE_ATTRIBUTES_PARAMETERS(), CHANGE_ATTRIBUTES_PARAMETERS
        ),
    ]


class ChangeAttributes_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class AssignDriveLetter_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0), NDRShortField("wcLetter", 0)]


class AssignDriveLetter_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class DeleteDriveLetter_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0), NDRShortField("wcLetter", 0)]


class DeleteDriveLetter_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class GetDriveLetter_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0)]


class GetDriveLetter_Response(NDRPacket):
    fields_desc = [NDRShortField("pwcLetter", 0), NDRIntField("status", 0)]


class FormatPartition_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRInt3264EnumField("type", 0, VDS_FILE_SYSTEM_TYPE),
        NDRConfVarStrNullFieldUtf16("pwszLabel", ""),
        NDRIntField("dwUnitAllocationSize", 0),
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bQuickFormat", 0),
        NDRSignedIntField("bEnableCompression", 0),
    ]


class FormatPartition_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class Clean_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bForceOEM", 0),
        NDRSignedIntField("bFullClean", 0),
    ]


class Clean_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSADVANCEDDISK_OPNUMS = {
    0: DceRpcOp(GetPartitionProperties_Request, GetPartitionProperties_Response),
    1: DceRpcOp(QueryPartitions_Request, QueryPartitions_Response),
    2: DceRpcOp(CreatePartition_Request, CreatePartition_Response),
    3: DceRpcOp(DeletePartition_Request, DeletePartition_Response),
    4: DceRpcOp(ChangeAttributes_Request, ChangeAttributes_Response),
    5: DceRpcOp(AssignDriveLetter_Request, AssignDriveLetter_Response),
    6: DceRpcOp(DeleteDriveLetter_Request, DeleteDriveLetter_Response),
    7: DceRpcOp(GetDriveLetter_Request, GetDriveLetter_Response),
    8: DceRpcOp(FormatPartition_Request, FormatPartition_Response),
    9: DceRpcOp(Clean_Request, Clean_Response),
}
register_com_interface(
    name="IVdsAdvancedDisk",
    uuid=uuid.UUID("6e6f6b40-977c-4069-bddd-ac710059f8c0"),
    opnums=IVDSADVANCEDDISK_OPNUMS,
)


class MbrPartInfo_sub0(NDRPacket):
    fields_desc = [NDRSignedByteField("partitionType", 0)]


class GptPartInfo_sub1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRPacketField("partitionType", GUID(), GUID)]


class CHANGE_PARTITION_TYPE_PARAMETERS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRInt3264EnumField("style", 0, VDS_PARTITION_STYLE),
        NDRUnionField(
            [
                (
                    NDRPacketField("value", MbrPartInfo_sub0(), MbrPartInfo_sub0),
                    (
                        (
                            lambda pkt: getattr(pkt, "style", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField("value", GptPartInfo_sub1(), GptPartInfo_sub1),
                    (
                        (
                            lambda pkt: getattr(pkt, "style", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 4),
            switch_fmt=("H", "I"),
        ),
    ]


class ChangePartitionType_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRSignedIntField("bForce", 0),
        NDRPacketField(
            "para", CHANGE_PARTITION_TYPE_PARAMETERS(), CHANGE_PARTITION_TYPE_PARAMETERS
        ),
    ]


class ChangePartitionType_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSADVANCEDDISK2_OPNUMS = {
    0: DceRpcOp(ChangePartitionType_Request, ChangePartitionType_Response)
}
register_com_interface(
    name="IVdsAdvancedDisk2",
    uuid=uuid.UUID("9723f420-9355-42de-ab66-e31bb15beeac"),
    opnums=IVDSADVANCEDDISK2_OPNUMS,
)


class VDS_ADVANCEDDISK_PROP(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszId", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszPathname", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszLocation", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszFriendlyName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pswzIdentifier", ""), deferred=True
        ),
        NDRShortField("usIdentifierFormat", 0),
        NDRIntField("ulNumber", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszSerialNumber", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszFirmwareVersion", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszManufacturer", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszModel", ""), deferred=True
        ),
        NDRLongField("ullTotalSize", 0),
        NDRLongField("ullAllocatedSize", 0),
        NDRIntField("ulLogicalSectorSize", 0),
        NDRIntField("ulPhysicalSectorSize", 0),
        NDRIntField("ulPartitionCount", 0),
        NDRInt3264EnumField("status", 0, VDS_DISK_STATUS),
        NDRInt3264EnumField("health", 0, VDS_HEALTH),
        NDRInt3264EnumField("BusType", 0, VDS_STORAGE_BUS_TYPE),
        NDRInt3264EnumField("PartitionStyle", 0, VDS_PARTITION_STYLE),
        NDRUnionField(
            [
                (
                    NDRIntField("value", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_MBR
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_MBR),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "PartitionStyle", None)
                            == VDS_PARTITION_STYLE.VDS_PST_GPT
                        ),
                        (lambda _, val: val.tag == VDS_PARTITION_STYLE.VDS_PST_GPT),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 4),
            switch_fmt=("H", "I"),
        ),
        NDRIntField("ulFlags", 0),
        NDRIntField("dwDeviceType", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pAdvDiskProp", VDS_ADVANCEDDISK_PROP(), VDS_ADVANCEDDISK_PROP),
        NDRIntField("status", 0),
    ]


class GetUniqueId_Request(NDRPacket):
    fields_desc = []


class GetUniqueId_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppwszId", "")),
        NDRIntField("status", 0),
    ]


IVDSADVANCEDDISK3_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(GetUniqueId_Request, GetUniqueId_Response),
}
register_com_interface(
    name="IVdsAdvancedDisk3",
    uuid=uuid.UUID("3858C0D5-0F35-4BF5-9714-69874963BC36"),
    opnums=IVDSADVANCEDDISK3_OPNUMS,
)


class CreatePartitionEx_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRLongField("ullSize", 0),
        NDRIntField("ulAlign", 0),
        NDRPacketField(
            "para", CREATE_PARTITION_PARAMETERS(), CREATE_PARTITION_PARAMETERS
        ),
    ]


class CreatePartitionEx_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSCREATEPARTITIONEX_OPNUMS = {
    0: DceRpcOp(CreatePartitionEx_Request, CreatePartitionEx_Response)
}
register_com_interface(
    name="IVdsCreatePartitionEx",
    uuid=uuid.UUID("9882f547-cfc3-420b-9750-00dfbec50662"),
    opnums=IVDSCREATEPARTITIONEX_OPNUMS,
)


class Online_Request(NDRPacket):
    fields_desc = []


class Online_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Offline_Request(NDRPacket):
    fields_desc = []


class Offline_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSDISKONLINE_OPNUMS = {
    0: DceRpcOp(Online_Request, Online_Response),
    1: DceRpcOp(Offline_Request, Offline_Response),
}
register_com_interface(
    name="IVdsDiskOnline",
    uuid=uuid.UUID("90681B1D-6A7F-48e8-9061-31B7AA125322"),
    opnums=IVDSDISKONLINE_OPNUMS,
)


class VDS_FILE_SYSTEM_PROP(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_FILE_SYSTEM_TYPE),
        NDRPacketField("volumeId", GUID(), GUID),
        NDRIntField("ulFlags", 0),
        NDRLongField("ullTotalAllocationUnits", 0),
        NDRLongField("ullAvailableAllocationUnits", 0),
        NDRIntField("ulAllocationUnitSize", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszLabel", ""), deferred=True
        ),
    ]


class GetPartitionFileSystemProperties_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0)]


class GetPartitionFileSystemProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pFileSystemProp", VDS_FILE_SYSTEM_PROP(), VDS_FILE_SYSTEM_PROP),
        NDRIntField("status", 0),
    ]


class GetPartitionFileSystemTypeName_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0)]


class GetPartitionFileSystemTypeName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppwszFileSystemTypeName", "")),
        NDRIntField("status", 0),
    ]


class VDS_FILE_SYSTEM_FORMAT_SUPPORT_PROP(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulFlags", 0),
        NDRShortField("usRevision", 0),
        NDRIntField("ulDefaultUnitAllocationSize", 0),
        NDRFieldListField(
            "rgulAllowedUnitAllocationSizes",
            [],
            NDRIntField("", 0),
            length_is=lambda _: 32,
        ),
        StrFixedLenFieldUtf16("wszName", "", length=32 * 2),
    ]


class QueryPartitionFileSystemFormatSupport_Request(NDRPacket):
    fields_desc = [NDRLongField("ullOffset", 0)]


class QueryPartitionFileSystemFormatSupport_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppFileSystemSupportProps",
            [],
            VDS_FILE_SYSTEM_FORMAT_SUPPORT_PROP,
            size_is=lambda pkt: pkt.plNumberOfFileSystems,
            ptr_pack=True,
        ),
        NDRSignedIntField(
            "plNumberOfFileSystems", None, size_of="ppFileSystemSupportProps"
        ),
        NDRIntField("status", 0),
    ]


class FormatPartitionEx_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszFileSystemTypeName", "")),
        NDRShortField("usFileSystemRevision", 0),
        NDRIntField("ulDesiredUnitAllocationSize", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszLabel", "")),
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bQuickFormat", 0),
        NDRSignedIntField("bEnableCompression", 0),
    ]


class FormatPartitionEx_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSDISKPARTITIONMF_OPNUMS = {
    0: DceRpcOp(
        GetPartitionFileSystemProperties_Request,
        GetPartitionFileSystemProperties_Response,
    ),
    1: DceRpcOp(
        GetPartitionFileSystemTypeName_Request, GetPartitionFileSystemTypeName_Response
    ),
    2: DceRpcOp(
        QueryPartitionFileSystemFormatSupport_Request,
        QueryPartitionFileSystemFormatSupport_Response,
    ),
    3: DceRpcOp(FormatPartitionEx_Request, FormatPartitionEx_Response),
}
register_com_interface(
    name="IVdsDiskPartitionMF",
    uuid=uuid.UUID("538684e0-ba3d-4bc0-aca9-164aff85c2a9"),
    opnums=IVDSDISKPARTITIONMF_OPNUMS,
)


class FormatPartitionEx2_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullOffset", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszFileSystemTypeName", "")),
        NDRShortField("usFileSystemRevision", 0),
        NDRIntField("ulDesiredUnitAllocationSize", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszLabel", "")),
        NDRIntField("Options", 0),
    ]


class FormatPartitionEx2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSDISKPARTITIONMF2_OPNUMS = {
    0: DceRpcOp(FormatPartitionEx2_Request, FormatPartitionEx2_Response)
}
register_com_interface(
    name="IVdsDiskPartitionMF2",
    uuid=uuid.UUID("9CBE50CA-F2D2-4bf4-ACE1-96896B729625"),
    opnums=IVDSDISKPARTITIONMF2_OPNUMS,
)


class QueryMedia_Request(NDRPacket):
    fields_desc = []


class QueryMedia_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Eject_Request(NDRPacket):
    fields_desc = []


class Eject_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSREMOVABLE_OPNUMS = {
    0: DceRpcOp(QueryMedia_Request, QueryMedia_Response),
    1: DceRpcOp(Eject_Request, Eject_Response),
}
register_com_interface(
    name="IVdsRemovable",
    uuid=uuid.UUID("0316560b-5db4-4ed9-bbb5-213436ddc0d9"),
    opnums=IVDSREMOVABLE_OPNUMS,
)


class VDS_VOLUME_STATUS(IntEnum):
    VDS_VS_UNKNOWN = 0
    VDS_VS_ONLINE = 1
    VDS_VS_NO_MEDIA = 3
    VDS_VS_OFFLINE = 4
    VDS_VS_FAILED = 5


class VDS_TRANSITION_STATE(IntEnum):
    VDS_TS_UNKNOWN = 0
    VDS_TS_STABLE = 1
    VDS_TS_EXTENDING = 2
    VDS_TS_SHRINKING = 3
    VDS_TS_RECONFIGING = 4


class VDS_VOLUME_PROP(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRInt3264EnumField("type", 0, VDS_VOLUME_TYPE),
        NDRInt3264EnumField("status", 0, VDS_VOLUME_STATUS),
        NDRInt3264EnumField("health", 0, VDS_HEALTH),
        NDRInt3264EnumField("TransitionState", 0, VDS_TRANSITION_STATE),
        NDRLongField("ullSize", 0),
        NDRIntField("ulFlags", 0),
        NDRInt3264EnumField("RecommendedFileSystemType", 0, VDS_FILE_SYSTEM_TYPE),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pVolumeProperties", VDS_VOLUME_PROP(), VDS_VOLUME_PROP),
        NDRIntField("status", 0),
    ]


class GetPack_Request(NDRPacket):
    fields_desc = []


class GetPack_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppPack", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class QueryPlexes_Request(NDRPacket):
    fields_desc = []


class QueryPlexes_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppEnum", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class Extend_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "pInputDiskArray",
            [],
            VDS_INPUT_DISK,
            size_is=lambda pkt: pkt.lNumberOfDisks,
        ),
        NDRSignedIntField("lNumberOfDisks", None, size_of="pInputDiskArray"),
    ]


class Extend_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class Shrink_Request(NDRPacket):
    fields_desc = [NDRLongField("ullNumberOfBytesToRemove", 0)]


class Shrink_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class AddPlex_Request(NDRPacket):
    fields_desc = [NDRPacketField("VolumeId", GUID(), GUID)]


class AddPlex_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class BreakPlex_Request(NDRPacket):
    fields_desc = [NDRPacketField("plexId", GUID(), GUID)]


class BreakPlex_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class RemovePlex_Request(NDRPacket):
    fields_desc = [NDRPacketField("plexId", GUID(), GUID)]


class RemovePlex_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class Delete_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("bForce", 0)]


class Delete_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class SetFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0), NDRSignedIntField("bRevertOnClose", 0)]


class SetFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class ClearFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class ClearFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSVOLUME_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(GetPack_Request, GetPack_Response),
    2: DceRpcOp(QueryPlexes_Request, QueryPlexes_Response),
    3: DceRpcOp(Extend_Request, Extend_Response),
    4: DceRpcOp(Shrink_Request, Shrink_Response),
    5: DceRpcOp(AddPlex_Request, AddPlex_Response),
    6: DceRpcOp(BreakPlex_Request, BreakPlex_Response),
    7: DceRpcOp(RemovePlex_Request, RemovePlex_Response),
    8: DceRpcOp(Delete_Request, Delete_Response),
    9: DceRpcOp(SetFlags_Request, SetFlags_Response),
    10: DceRpcOp(ClearFlags_Request, ClearFlags_Response),
}
register_com_interface(
    name="IVdsVolume",
    uuid=uuid.UUID("88306bb2-e71f-478c-86a2-79da200a0f11"),
    opnums=IVDSVOLUME_OPNUMS,
)


class VDS_VOLUME_PROP2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRInt3264EnumField("type", 0, VDS_VOLUME_TYPE),
        NDRInt3264EnumField("status", 0, VDS_VOLUME_STATUS),
        NDRInt3264EnumField("health", 0, VDS_HEALTH),
        NDRInt3264EnumField("TransitionState", 0, VDS_TRANSITION_STATE),
        NDRLongField("ullSize", 0),
        NDRIntField("ulFlags", 0),
        NDRInt3264EnumField("RecommendedFileSystemType", 0, VDS_FILE_SYSTEM_TYPE),
        NDRIntField("cbUniqueId", None, size_of="pUniqueId"),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszName", ""), deferred=True),
        NDRFullPointerField(
            NDRConfStrLenField("pUniqueId", "", size_is=lambda pkt: pkt.cbUniqueId),
            deferred=True,
        ),
    ]


class GetProperties2_Request(NDRPacket):
    fields_desc = []


class GetProperties2_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pVolumeProperties", VDS_VOLUME_PROP2(), VDS_VOLUME_PROP2),
        NDRIntField("status", 0),
    ]


IVDSVOLUME2_OPNUMS = {0: DceRpcOp(GetProperties2_Request, GetProperties2_Response)}
register_com_interface(
    name="IVdsVolume2",
    uuid=uuid.UUID("72AE6713-DCBB-4a03-B36B-371F6AC6B53D"),
    opnums=IVDSVOLUME2_OPNUMS,
)


class GetFileSystemProperties_Request(NDRPacket):
    fields_desc = []


class GetFileSystemProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pFileSystemProp", VDS_FILE_SYSTEM_PROP(), VDS_FILE_SYSTEM_PROP),
        NDRIntField("status", 0),
    ]


class Format_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("type", 0, VDS_FILE_SYSTEM_TYPE),
        NDRConfVarStrNullFieldUtf16("pwszLabel", ""),
        NDRIntField("dwUnitAllocationSize", 0),
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bQuickFormat", 0),
        NDRSignedIntField("bEnableCompression", 0),
    ]


class Format_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class AddAccessPath_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "pwszPath", "", size_is=lambda pkt: (pkt.MAX_PATH - 1)
        )
    ]


class AddAccessPath_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class QueryAccessPaths_Request(NDRPacket):
    fields_desc = []


class QueryAccessPaths_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "pwszPathArray", "", size_is=lambda pkt: pkt.plNumberOfAccessPaths
        ),
        NDRSignedIntField("plNumberOfAccessPaths", None, size_of="pwszPathArray"),
        NDRIntField("status", 0),
    ]


class PVDS_REPARSE_POINT_PROP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("SourceVolumeId", GUID(), GUID),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "pwszPath", "", size_is=lambda pkt: (pkt.MAX_PATH - 1)
            ),
            deferred=True,
        ),
    ]


class QueryReparsePoints_Request(NDRPacket):
    fields_desc = []


class QueryReparsePoints_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppReparsePointProps",
            [],
            PVDS_REPARSE_POINT_PROP,
            size_is=lambda pkt: pkt.plNumberOfReparsePointProps,
            ptr_pack=True,
        ),
        NDRSignedIntField(
            "plNumberOfReparsePointProps", None, size_of="ppReparsePointProps"
        ),
        NDRIntField("status", 0),
    ]


class DeleteAccessPath_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "pwszPath", "", size_is=lambda pkt: (pkt.MAX_PATH - 1)
        ),
        NDRSignedIntField("bForce", 0),
    ]


class DeleteAccessPath_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Mount_Request(NDRPacket):
    fields_desc = []


class Mount_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class Dismount_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("bForce", 0), NDRSignedIntField("bPermanent", 0)]


class Dismount_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class SetFileSystemFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class SetFileSystemFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class ClearFileSystemFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("ulFlags", 0)]


class ClearFileSystemFlags_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSVOLUMEMF_OPNUMS = {
    0: DceRpcOp(GetFileSystemProperties_Request, GetFileSystemProperties_Response),
    1: DceRpcOp(Format_Request, Format_Response),
    2: DceRpcOp(AddAccessPath_Request, AddAccessPath_Response),
    3: DceRpcOp(QueryAccessPaths_Request, QueryAccessPaths_Response),
    4: DceRpcOp(QueryReparsePoints_Request, QueryReparsePoints_Response),
    5: DceRpcOp(DeleteAccessPath_Request, DeleteAccessPath_Response),
    6: DceRpcOp(Mount_Request, Mount_Response),
    7: DceRpcOp(Dismount_Request, Dismount_Response),
    8: DceRpcOp(SetFileSystemFlags_Request, SetFileSystemFlags_Response),
    9: DceRpcOp(ClearFileSystemFlags_Request, ClearFileSystemFlags_Response),
}
register_com_interface(
    name="IVdsVolumeMF",
    uuid=uuid.UUID("ee2d5ded-6236-4169-931d-b9778ce03dc6"),
    opnums=IVDSVOLUMEMF_OPNUMS,
)


class GetFileSystemTypeName_Request(NDRPacket):
    fields_desc = []


class GetFileSystemTypeName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppwszFileSystemTypeName", "")),
        NDRIntField("status", 0),
    ]


class QueryFileSystemFormatSupport_Request(NDRPacket):
    fields_desc = []


class QueryFileSystemFormatSupport_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppFileSystemSupportProps",
            [],
            VDS_FILE_SYSTEM_FORMAT_SUPPORT_PROP,
            size_is=lambda pkt: pkt.plNumberOfFileSystems,
            ptr_pack=True,
        ),
        NDRSignedIntField(
            "plNumberOfFileSystems", None, size_of="ppFileSystemSupportProps"
        ),
        NDRIntField("status", 0),
    ]


class FormatEx_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszFileSystemTypeName", "")),
        NDRShortField("usFileSystemRevision", 0),
        NDRIntField("ulDesiredUnitAllocationSize", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszLabel", "")),
        NDRSignedIntField("bForce", 0),
        NDRSignedIntField("bQuickFormat", 0),
        NDRSignedIntField("bEnableCompression", 0),
    ]


class FormatEx_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSVOLUMEMF2_OPNUMS = {
    0: DceRpcOp(GetFileSystemTypeName_Request, GetFileSystemTypeName_Response),
    1: DceRpcOp(
        QueryFileSystemFormatSupport_Request, QueryFileSystemFormatSupport_Response
    ),
    2: DceRpcOp(FormatEx_Request, FormatEx_Response),
}
register_com_interface(
    name="IVdsVolumeMF2",
    uuid=uuid.UUID("4dbcee9a-6343-4651-b85f-5e75d74d983c"),
    opnums=IVDSVOLUMEMF2_OPNUMS,
)


class QueryVolumeGuidPathnames_Request(NDRPacket):
    fields_desc = []


class QueryVolumeGuidPathnames_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "pwszPathArray", "", size_is=lambda pkt: pkt.pulNumberOfPaths
        ),
        NDRIntField("pulNumberOfPaths", None, size_of="pwszPathArray"),
        NDRIntField("status", 0),
    ]


class FormatEx2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszFileSystemTypeName", "")),
        NDRShortField("usFileSystemRevision", 0),
        NDRIntField("ulDesiredUnitAllocationSize", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszLabel", "")),
        NDRIntField("Options", 0),
    ]


class FormatEx2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class OfflineVolume_Request(NDRPacket):
    fields_desc = []


class OfflineVolume_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSVOLUMEMF3_OPNUMS = {
    0: DceRpcOp(QueryVolumeGuidPathnames_Request, QueryVolumeGuidPathnames_Response),
    1: DceRpcOp(FormatEx2_Request, FormatEx2_Response),
    2: DceRpcOp(OfflineVolume_Request, OfflineVolume_Response),
}
register_com_interface(
    name="IVdsVolumeMF3",
    uuid=uuid.UUID("6788FAF9-214E-4b85-BA59-266953616E09"),
    opnums=IVDSVOLUMEMF3_OPNUMS,
)


class QueryMaxReclaimableBytes_Request(NDRPacket):
    fields_desc = []


class QueryMaxReclaimableBytes_Response(NDRPacket):
    fields_desc = [
        NDRLongField("pullMaxNumberOfReclaimableBytes", 0),
        NDRIntField("status", 0),
    ]


class Shrink_Request(NDRPacket):
    fields_desc = [
        NDRLongField("ullDesiredNumberOfReclaimableBytes", 0),
        NDRLongField("ullMinNumberOfReclaimableBytes", 0),
    ]


class Shrink_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSVOLUMESHRINK_OPNUMS = {
    0: DceRpcOp(QueryMaxReclaimableBytes_Request, QueryMaxReclaimableBytes_Response),
    1: DceRpcOp(Shrink_Request, Shrink_Response),
}
register_com_interface(
    name="IVdsVolumeShrink",
    uuid=uuid.UUID("d68168c9-82a2-4f85-b6e9-74707c49a58f"),
    opnums=IVDSVOLUMESHRINK_OPNUMS,
)


class Online_Request(NDRPacket):
    fields_desc = []


class Online_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


IVDSVOLUMEONLINE_OPNUMS = {0: DceRpcOp(Online_Request, Online_Response)}
register_com_interface(
    name="IVdsVolumeOnline",
    uuid=uuid.UUID("1BE2275A-B315-4f70-9E44-879B3A2A53F2"),
    opnums=IVDSVOLUMEONLINE_OPNUMS,
)


class VDS_VOLUME_PLEX_TYPE(IntEnum):
    VDS_VPT_UNKNOWN = 0
    VDS_VPT_SIMPLE = 10
    VDS_VPT_SPAN = 11
    VDS_VPT_STRIPE = 12
    VDS_VPT_PARITY = 14


class VDS_VOLUME_PLEX_STATUS(IntEnum):
    VDS_VPS_UNKNOWN = 0
    VDS_VPS_ONLINE = 1
    VDS_VPS_NO_MEDIA = 3
    VDS_VPS_FAILED = 5


class VDS_VOLUME_PLEX_PROP(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("id", GUID(), GUID),
        NDRInt3264EnumField("type", 0, VDS_VOLUME_PLEX_TYPE),
        NDRInt3264EnumField("status", 0, VDS_VOLUME_PLEX_STATUS),
        NDRInt3264EnumField("health", 0, VDS_HEALTH),
        NDRInt3264EnumField("TransitionState", 0, VDS_TRANSITION_STATE),
        NDRLongField("ullSize", 0),
        NDRIntField("ulStripeSize", 0),
        NDRIntField("ulNumberOfMembers", 0),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pPlexProperties", VDS_VOLUME_PLEX_PROP(), VDS_VOLUME_PLEX_PROP),
        NDRIntField("status", 0),
    ]


class GetVolume_Request(NDRPacket):
    fields_desc = []


class GetVolume_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppVolume", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class QueryExtents_Request(NDRPacket):
    fields_desc = []


class QueryExtents_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppExtentArray",
            [],
            VDS_DISK_EXTENT,
            size_is=lambda pkt: pkt.plNumberOfExtents,
            ptr_pack=True,
        ),
        NDRSignedIntField("plNumberOfExtents", None, size_of="ppExtentArray"),
        NDRIntField("status", 0),
    ]


class Repair_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "pInputDiskArray",
            [],
            VDS_INPUT_DISK,
            size_is=lambda pkt: pkt.lNumberOfDisks,
        ),
        NDRSignedIntField("lNumberOfDisks", None, size_of="pInputDiskArray"),
    ]


class Repair_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSVOLUMEPLEX_OPNUMS = {
    0: DceRpcOp(GetProperties_Request, GetProperties_Response),
    1: DceRpcOp(GetVolume_Request, GetVolume_Response),
    2: DceRpcOp(QueryExtents_Request, QueryExtents_Response),
    3: DceRpcOp(Repair_Request, Repair_Response),
}
register_com_interface(
    name="IVdsVolumePlex",
    uuid=uuid.UUID("4daa0135-e1d1-40f1-aaa5-3cc1e53221c3"),
    opnums=IVDSVOLUMEPLEX_OPNUMS,
)


class VIRTUAL_DISK_ACCESS_MASK(IntEnum):
    VIRTUAL_DISK_ACCESS_SURFACE_RO = 65536
    VIRTUAL_DISK_ACCESS_SURFACE_RW = 131072
    VIRTUAL_DISK_ACCESS_UNSURFACE = 262144
    VIRTUAL_DISK_ACCESS_GET_INFO = 524288
    VIRTUAL_DISK_ACCESS_CREATE = 1048576
    VIRTUAL_DISK_ACCESS_METAOPS = 2097152
    VIRTUAL_DISK_ACCESS_READ = 851968
    VIRTUAL_DISK_ACCESS_ALL = 4128768
    VIRTUAL_DISK_ACCESS_WRITABLE = 3276800


class OPEN_VIRTUAL_DISK_FLAG(IntEnum):
    OPEN_VIRTUAL_DISK_FLAG_NONE = 0
    OPEN_VIRTUAL_DISK_FLAG_NO_PARENTS = 1
    OPEN_VIRTUAL_DISK_FLAG_BLANK_FILE = 2
    OPEN_VIRTUAL_DISK_FLAG_BOOT_DRIVE = 4


class Open_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("AccessMask", 0, VIRTUAL_DISK_ACCESS_MASK),
        NDRInt3264EnumField("Flags", 0, OPEN_VIRTUAL_DISK_FLAG),
        NDRIntField("ReadWriteDepth", 0),
    ]


class Open_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppOpenVDisk", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class VDS_VDISK_STATE(IntEnum):
    VDS_VST_UNKNOWN = 0
    VDS_VST_ADDED = 1
    VDS_VST_OPEN = 2
    VDS_VST_ATTACH_PENDING = 3
    VDS_VST_ATTACHED_NOT_OPEN = 4
    VDS_VST_ATTACHED = 5
    VDS_VST_DETACH_PENDING = 6
    VDS_VST_COMPACTING = 7
    VDS_VST_MERGING = 8
    VDS_VST_EXPANDING = 9
    VDS_VST_DELETED = 10
    VDS_VST_MAX = 11


class VIRTUAL_STORAGE_TYPE(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("DeviceId", 0), NDRPacketField("VendorId", GUID(), GUID)]


class DEPENDENT_DISK_FLAG(IntEnum):
    DEPENDENT_DISK_FLAG_NONE = 0
    DEPENDENT_DISK_FLAG_MULT_BACKING_FILES = 1
    DEPENDENT_DISK_FLAG_FULLY_ALLOCATED = 2
    DEPENDENT_DISK_FLAG_READ_ONLY = 4
    DEPENDENT_DISK_FLAG_REMOTE = 8
    DEPENDENT_DISK_FLAG_SYSTEM_VOLUME = 16
    DEPENDENT_DISK_FLAG_SYSTEM_VOLUME_PARENT = 32
    DEPENDENT_DISK_FLAG_REMOVABLE = 64
    DEPENDENT_DISK_FLAG_NO_DRIVE_LETTER = 128
    DEPENDENT_DISK_FLAG_PARENT = 256
    DEPENDENT_DISK_FLAG_NO_HOST_DISK = 512
    DEPENDENT_DISK_FLAG_PERMANENT_LIFETIME = 1024


class PVDS_VDISK_PROPERTIES(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("Id", GUID(), GUID),
        NDRInt3264EnumField("State", 0, VDS_VDISK_STATE),
        NDRPacketField(
            "VirtualDeviceType", VIRTUAL_STORAGE_TYPE(), VIRTUAL_STORAGE_TYPE
        ),
        NDRLongField("VirtualSize", 0),
        NDRLongField("PhysicalSize", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pPath", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pDeviceName", ""), deferred=True
        ),
        NDRInt3264EnumField("DiskFlag", 0, DEPENDENT_DISK_FLAG),
        NDRSignedIntField("bIsChild", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pParentPath", ""), deferred=True
        ),
    ]


class GetProperties_Request(NDRPacket):
    fields_desc = []


class GetProperties_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "pDiskProperties", PVDS_VDISK_PROPERTIES(), PVDS_VDISK_PROPERTIES
        ),
        NDRIntField("status", 0),
    ]


class GetHostVolume_Request(NDRPacket):
    fields_desc = []


class GetHostVolume_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppVolume", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class GetDeviceName_Request(NDRPacket):
    fields_desc = []


class GetDeviceName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppDeviceName", "")),
        NDRIntField("status", 0),
    ]


IVDSVDISK_OPNUMS = {
    0: DceRpcOp(Open_Request, Open_Response),
    1: DceRpcOp(GetProperties_Request, GetProperties_Response),
    2: DceRpcOp(GetHostVolume_Request, GetHostVolume_Response),
    3: DceRpcOp(GetDeviceName_Request, GetDeviceName_Response),
}
register_com_interface(
    name="IVdsVDisk",
    uuid=uuid.UUID("1e062b84-e5e6-4b4b-8a25-67b81e8f13e8"),
    opnums=IVDSVDISK_OPNUMS,
)


class ATTACH_VIRTUAL_DISK_FLAG(IntEnum):
    ATTACH_VIRTUAL_DISK_FLAG_NONE = 0
    ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY = 1
    ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER = 2
    ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME = 4
    ATTACH_VIRTUAL_DISK_FLAG_NO_LOCAL_HOST = 8


class Attach_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("pStringSecurityDescriptor", 0)),
        NDRInt3264EnumField("Flags", 0, ATTACH_VIRTUAL_DISK_FLAG),
        NDRIntField("ProviderSpecificFlags", 0),
        NDRIntField("TimeoutInMs", 0),
    ]


class Attach_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class DETACH_VIRTUAL_DISK_FLAG(IntEnum):
    DETACH_VIRTUAL_DISK_FLAG_NONE = 0


class Detach_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("Flags", 0, DETACH_VIRTUAL_DISK_FLAG),
        NDRIntField("ProviderSpecificFlags", 0),
    ]


class Detach_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class DetachAndDelete_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("Flags", 0, DETACH_VIRTUAL_DISK_FLAG),
        NDRIntField("ProviderSpecificFlags", 0),
    ]


class DetachAndDelete_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class COMPACT_VIRTUAL_DISK_FLAG(IntEnum):
    COMPACT_VIRTUAL_DISK_FLAG_NONE = 0


class Compact_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("Flags", 0, COMPACT_VIRTUAL_DISK_FLAG),
        NDRIntField("Reserved", 0),
    ]


class Compact_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class MERGE_VIRTUAL_DISK_FLAG(IntEnum):
    MERGE_VIRTUAL_DISK_FLAG_NONE = 0


class Merge_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("Flags", 0, MERGE_VIRTUAL_DISK_FLAG),
        NDRIntField("MergeDepth", 0),
    ]


class Merge_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class EXPAND_VIRTUAL_DISK_FLAG(IntEnum):
    EXPAND_VIRTUAL_DISK_FLAG_NONE = 0


class Expand_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("Flags", 0, EXPAND_VIRTUAL_DISK_FLAG),
        NDRLongField("NewSize", 0),
    ]


class Expand_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppAsync", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IVDSOPENVDISK_OPNUMS = {
    0: DceRpcOp(Attach_Request, Attach_Response),
    1: DceRpcOp(Detach_Request, Detach_Response),
    2: DceRpcOp(DetachAndDelete_Request, DetachAndDelete_Response),
    3: DceRpcOp(Compact_Request, Compact_Response),
    4: DceRpcOp(Merge_Request, Merge_Response),
    5: DceRpcOp(Expand_Request, Expand_Response),
}
register_com_interface(
    name="IVdsOpenVDisk",
    uuid=uuid.UUID("75c8f324-f715-4fe3-a28e-f9011b61a4a1"),
    opnums=IVDSOPENVDISK_OPNUMS,
)
