how to use IOCTL_STORAGE_SET_PROPERTY for setting UFS flag?

surfacer 1 Reputation point
2022-08-18T08:28:09.407+00:00

Hi,

I'm able to get UFS device Descriptors/Attributes/Flags with IOCTL_STORAGE_QUERY_PROPERTY

but when trying to set Descriptors/Attributes/Flags using IOCTL_STORAGE_SET_PROPERTY, the IOCTL fail.

can you please add some examples how to use this IOCTL with UFS device?

I tried to adjust the NVMe code from here: https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/FileIO/working-with-nvme-devices.md for UFS, but it fails

please advise,

Thanks

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,138 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 43,931 Reputation points
    2022-08-19T14:04:42.647+00:00

    Hi Benny,

    Try copying this code and check it .

    File Index Symbol Index

    /*++ BUILD Version: 0032    // Increment this if a change has global effects  
      
    Copyright (c) Microsoft Corporation. All rights reserved.  
      
    Module Name:  
      
        winioctl.h  
      
    Abstract:  
      
        This module defines the 32-Bit Windows Device I/O control codes.  
      
    Revision History:  
      
    --*/  
      
      
    //  
    // Device interface class GUIDs.  
    //  
    // need these GUIDs outside conditional includes so that user can  
    //   #include <winioctl.h> in precompiled header  
    //   #include <initguid.h> in a single source file  
    //   #include <winioctl.h> in that source file a second time to instantiate the GUIDs  
    //  
    #ifdef DEFINE_GUID  
    //  
    // Make sure FAR is defined...  
    //  
    #ifndef FAR  
    #ifdef _WIN32  
    #define FAR  
    #else  
    #define FAR _far  
    #endif  
    #endif  
      
      
    #ifndef __WRAPPED__  
    #define __WRAPPED__  
    #endif  
      
    DEFINE_GUID(GUID_DEVINTERFACE_DISK,                   0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_DISK;  
    DEFINE_GUID(GUID_DEVINTERFACE_CDROM,                  0x53f56308L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_CDROM;  
    DEFINE_GUID(GUID_DEVINTERFACE_PARTITION,              0x53f5630aL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_PARTITION;  
    DEFINE_GUID(GUID_DEVINTERFACE_TAPE,                   0x53f5630bL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_TAPE;  
    DEFINE_GUID(GUID_DEVINTERFACE_WRITEONCEDISK,          0x53f5630cL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_WRITEONCEDISK;  
    DEFINE_GUID(GUID_DEVINTERFACE_VOLUME,                 0x53f5630dL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_VOLUME;  
    DEFINE_GUID(GUID_DEVINTERFACE_MEDIUMCHANGER,          0x53f56310L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_MEDIUMCHANGER;  
    DEFINE_GUID(GUID_DEVINTERFACE_FLOPPY,                 0x53f56311L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_FLOPPY;  
    DEFINE_GUID(GUID_DEVINTERFACE_CDCHANGER,              0x53f56312L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_CDCHANGER;  
    DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,            0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82, 0x00, 0xa0, **********************);  
    extern "C" const GUID  GUID_DEVINTERFACE_STORAGEPORT;  
    DEFINE_GUID(GUID_DEVINTERFACE_VMLUN,                  0x6f416619L, 0x9f29, 0x42a5, 0xb2, 0x0b, 0x37, 0xe2, 0x19, 0xca, 0x02, 0xb0);  
    extern "C" const GUID  GUID_DEVINTERFACE_VMLUN;  
    DEFINE_GUID(GUID_DEVINTERFACE_SES,                    0x1790c9ecL, 0x47d5, 0x4df3, 0xb5, 0xaf, 0x9a, 0xdf, 0x3c, 0xf2, 0x3e, 0x48);  
    extern "C" const GUID  GUID_DEVINTERFACE_SES;  
      
    #define  WDI_STORAGE_PREDICT_FAILURE_DPS_GUID        {0xe9f2d03aL, 0x747c, 0x41c2, {0xbb, 0x9a, 0x02, ****************************}};  
      
    //  
    // Interfaces to discover devices that are  
    // not reported  through conventional APIs  
    //  
      
    DEFINE_GUID(GUID_DEVINTERFACE_SERVICE_VOLUME,         0x6ead3d82L, 0x25ec, 0x46bc, 0xb7, 0xfd, 0xc1, 0xf0, 0xdf, 0x8f, 0x50, 0x37);  
    extern "C" const GUID  GUID_DEVINTERFACE_SERVICE_VOLUME;  
    DEFINE_GUID(GUID_DEVINTERFACE_HIDDEN_VOLUME,          0x7f108a28L, 0x9833, 0x4b3b, 0xb7, 0x80, 0x2c, 0x6b, 0x5f, 0xa5, 0xc0, 0x62);  
    extern "C" const GUID  GUID_DEVINTERFACE_HIDDEN_VOLUME;  
      
    //  
    // Interface to register for RPMB commands  
    //  
      
    DEFINE_GUID(GUID_DEVINTERFACE_UNIFIED_ACCESS_RPMB,    0x27447c21L, 0xbcc3, 0x4d07, 0xa0, 0x5b, 0xa3, 0x39, 0x5b, 0xb4, 0xee, 0xe7);  
    extern "C" const GUID  GUID_DEVINTERFACE_UNIFIED_ACCESS_RPMB;  
      
      
    //  
    // This interface represents a physical persistent memory device, such as an NVDIMM.  
    // {4283609D-4DC2-43BE-BBB4-4F15DFCE2C61}  
    //  
    DEFINE_GUID(GUID_DEVINTERFACE_SCM_PHYSICAL_DEVICE, 0x4283609d, 0x4dc2, 0x43be, 0xbb, 0xb4, 0x4f, 0x15, 0xdf, 0xce, 0x2c, 0x61);  
    extern "C" const GUID  GUID_DEVINTERFACE_SCM_PHYSICAL_DEVICE;  
      
    //  
    // When a physical device driver detects a change in the health status of a physical device,  
    // it triggers a PNP custom event (through TARGET_DEVICE_CUSTOM_NOTIFICATION) to alert any  
    // registered components. The custom event's GUID is GUID_SCM_PD_HEALTH_NOTIFICATION  
    // and its payload is SCM_PD_HEALTH_NOTIFICATION_DATA  
    // {9DA2D386-72F5-4EE3-8155-ECA0678E3B06}  
    //  
    DEFINE_GUID(GUID_SCM_PD_HEALTH_NOTIFICATION, 0x9da2d386, 0x72f5, 0x4ee3, 0x81, 0x55, 0xec, 0xa0, 0x67, 0x8e, 0x3b, 0x6);  
    extern "C" const GUID  GUID_SCM_PD_HEALTH_NOTIFICATION;  
      
    //  
    // The passthrough protocol GUID for INVDIMM devices. The application and the driver use this value  
    // for the "ProtocolGuid" field of the SCM_PD_PASSTHROUGH_INPUT and SCM_PD_PASSTHROUGH_OUTPUT structures.  
    // {4309AC30-0D11-11E4-9191-0800200C9A66}  
    //  
    DEFINE_GUID(GUID_SCM_PD_PASSTHROUGH_INVDIMM, 0x4309AC30, 0x0D11, 0x11E4, 0x91, 0x91, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66);  
    extern "C" const GUID  GUID_SCM_PD_PASSTHROUGH_INVDIMM;  
      
    // {86E0D1E0-8089-11D0-9CE4-08003E301F73}  
    DEFINE_GUID(GUID_DEVINTERFACE_COMPORT,                0X86E0D1E0L, 0X8089, 0X11D0, 0X9C, 0XE4, 0X08, 0X00, 0X3E, 0X30, 0X1F, 0X73);  
    extern "C" const GUID  GUID_DEVINTERFACE_COMPORT;  
    // {4D36E978-E325-11CE-BFC1-08002BE10318}  
    DEFINE_GUID(GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR, 0x4D36E978L, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18);  
    extern "C" const GUID  GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR;  
      
    //  
    // Obsolete device interface class GUID names.  
    // (use of above GUID_DEVINTERFACE_* names is recommended).  
    //  
      
    #ifndef __WRAPPED__  
    #define __WRAPPED__  
    #endif  
      
    #define DiskClassGuid               GUID_DEVINTERFACE_DISK  
    #define CdRomClassGuid              GUID_DEVINTERFACE_CDROM  
    #define PartitionClassGuid          GUID_DEVINTERFACE_PARTITION  
    #define TapeClassGuid               GUID_DEVINTERFACE_TAPE  
    #define WriteOnceDiskClassGuid      GUID_DEVINTERFACE_WRITEONCEDISK  
    #define VolumeClassGuid             GUID_DEVINTERFACE_VOLUME  
    #define MediumChangerClassGuid      GUID_DEVINTERFACE_MEDIUMCHANGER  
    #define FloppyClassGuid             GUID_DEVINTERFACE_FLOPPY  
    #define CdChangerClassGuid          GUID_DEVINTERFACE_CDCHANGER  
    #define StoragePortClassGuid        GUID_DEVINTERFACE_STORAGEPORT  
      
    #define HiddenVolumeClassGuid       GUID_DEVINTERFACE_HIDDEN_VOLUME  
      
    #define GUID_CLASS_COMPORT          GUID_DEVINTERFACE_COMPORT  
    #define GUID_SERENUM_BUS_ENUMERATOR GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR  
      
    #endif // DEFINE_GUID  
      
    //  
    // Interface DEVPROPKEY  
    //  
    // need these DEVPROPKEYs outside conditional includes so that user can  
    //   #include <winioctl.h> in precompiled header  
    //   #include <devpropdef.h> in a single source file  
    //   #include <winioctl.h> in that source file a second time to instantiate the DEVPROPKEYs  
    //  
    #ifdef DEFINE_DEVPROPKEY  
      
      
    #ifndef __WRAPPED__  
    #define __WRAPPED__  
    #endif  
      
    //  
    // Properties associated with the volume interface.  
    //  
      
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Portable,           0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 2);    // DEVPROP_TYPE_BOOLEAN  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Removable_Media,    0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 3);    // DEVPROP_TYPE_BOOLEAN  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_System_Critical,    0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 4);    // DEVPROP_TYPE_BOOLEAN  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Disk_Number,        0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 5);    // DEVPROP_TYPE_UINT32  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Partition_Number,   0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 6);    // DEVPROP_TYPE_UINT32  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Mbr_Type,           0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 7);    // DEVPROP_TYPE_BYTE  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Gpt_Type,           0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 8);    // DEVPROP_TYPE_GUID  
    DEFINE_DEVPROPKEY(DEVPKEY_Storage_Gpt_Name,           0x4d1ebee8, 0x803, 0x4774, 0x98, 0x42, 0xb7, 0x7d, 0xb5, 0x2, 0x65, 0xe9, 9);    // DEVPROP_TYPE_STRING  
      
    #endif // DEFINE_DEVPROPKEY  
      
    #ifndef _WINIOCTL_  
    #define _WINIOCTL_  
      
    #if _MSC_VER >= 1200  
    #pragma warning(push)  
    #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union  
    #pragma warning(disable:4201)   
    #pragma warning(disable:4820) // padding added after data member  
    #endif  
    #pragma warning(disable:4820)   
      
      
    #ifndef _DEVIOCTL_  
    #define _DEVIOCTL_  
      
    // begin_ntddk begin_wdm begin_nthal begin_ntifs  
    //  
    // Define the various device type values.  Note that values used by Microsoft  
    // Corporation are in the range 0-32767, and 32768-65535 are reserved for use  
    // by customers.  
    //  
      
    #define DEVICE_TYPE DWORD  
      
    #define FILE_DEVICE_BEEP                0x00000001  
    #define FILE_DEVICE_CD_ROM              0x00000002  
    #define FILE_DEVICE_CD_ROM_FILE_SYSTEM  0x00000003  
    #define FILE_DEVICE_CONTROLLER          0x00000004  
    #define FILE_DEVICE_DATALINK            0x00000005  
    #define FILE_DEVICE_DFS                 0x00000006  
    #define FILE_DEVICE_DISK                0x00000007  
    #define FILE_DEVICE_DISK_FILE_SYSTEM    0x00000008  
    #define FILE_DEVICE_FILE_SYSTEM         0x00000009  
    #define FILE_DEVICE_INPORT_PORT         0x0000000a  
    #define FILE_DEVICE_KEYBOARD            0x0000000b  
    #define FILE_DEVICE_MAILSLOT            0x0000000c  
    #define FILE_DEVICE_MIDI_IN             0x0000000d  
    #define FILE_DEVICE_MIDI_OUT            0x0000000e  
    #define FILE_DEVICE_MOUSE               0x0000000f  
    #define FILE_DEVICE_MULTI_UNC_PROVIDER  0x00000010  
    #define FILE_DEVICE_NAMED_PIPE          0x00000011  
    #define FILE_DEVICE_NETWORK             0x00000012  
    #define FILE_DEVICE_NETWORK_BROWSER     0x00000013  
    #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x000000  
    

    ---

    If this solves your query please select this as an answer