[python-win32] 8G USB sector number

Tim Roberts timr at probo.com
Wed Aug 8 21:32:55 CEST 2012


Jane Chen wrote:
> Hi all,
> I would like to get total sector number of my disk. However, I found that I cannot get 8G sectors because of the buffer size.
>  I only got 4G.
>  
>         buf_fmt='LL'                       
>         buf_size=struct.calcsize(buf_fmt)
>         buf=win32file.DeviceIoControl(h, winioctlcon.IOCTL_DISK_GET_LENGTH_INFO, None, buf_size, None)
> Could someone please tell me how to get the total sector number?

I'm not sure what you mean here.  IOCTL_DISK_GET_LENGTH_INFO doesn't
return sectors -- it returns bytes, and it returns them as a 64-bit
integer.  That will hold almost 2 exabytes, about a million times larger
than any hard disks that exist today.

If you follow that sequence with
    print struct.unpack('Q',buf)[0]
you should see the length in bytes.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list