title: How to get raw disk or block device size in Windows with Python
body: <p>How do I get the size from a block device or raw disk in Windows if I only know the device name is "\.\PhysicalDrive0" with no file system on it or volume label? </p>
  
  <p>I tried the following: </p>
  
  <blockquote>
    <p>fd = os.open(r"\.\PhysicalDrive0", os.O_RDONLY)</p>
    
    <p>os.lseek(fd, 0, os.SEEK_END)</p>
  </blockquote>
  
  <p>it works fine on Linux but always return "OSError: [Errno 22] Invalid argument" on Windows.</p>
  
  <p>I also tried the ctypes.windll.kernel32.GetDiskFreeSpaceExW(), but it seems only work for disk with filesystem and assigned volume label. </p>
  
  <p>What's the proper way to do this for raw disk or block device? </p>
  
  <p>Thanks in advance. </p>