After partition was created using IOCTL_DISK_SET_DRIVE_LAYOUT, how do I create new volume in this newly created partition?

。_饼干妹妹 提交于 2019-12-23 00:27:09

问题


I am trying to create a new partition, format it and assign it a new drive letter via Python ctypes, using IOCTL_SET_DRIVE_LAYOUT. My initial coding attempt was done using this SO page : Python ctypes structure being overwritten when allocating more memory. You can see the definition of class DeviceIoControl there.

I successfully initialize the disk using IOCTL_DISK_CREATE_DISK, and create a new partition having certain size using IOCTL_DISK_SET_DRIVE_LAYOUT, below are the result in Disk Management:

.. but then, how do I create new volume in disk newly created partition?

I've try to use format method of Win32_Volume, but Win32_Volume only return all the n existing drive letters attached to existing partitions, while in my case, that drive letter is not assigned yet.

Any advice?


回答1:


Long story short (it really is a long story!), turn out, I mistakenly choose a wrong PartitionType. Previously I use PARTITION_EXTENDED 0x05, which after I experiment with another value : PARTITION_IFS 0x07, Windows directly asked me to format the partition. And to avoid this, as asked here, we have to wait for several seconds for the new drive letter to be available, and then call kernel32.GetLogicalDriveStringsA to query the new drive (you have to call this previously before creating the partition, and comparing the two, you will get the new drive letter). As the drive letter available, we can easily call Win32_Volume Format method to format the drive.

This is a mix of low level kernel32 call + WMI that bring about a successful solution for this problem. It will be way easier for us if all the functions were available in WMI. But, yeah, that's not we encounter here.



来源:https://stackoverflow.com/questions/23257643/after-partition-was-created-using-ioctl-disk-set-drive-layout-how-do-i-create-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!