0

I'm trying to read data directly from a specific partition on Windows 7 in Python.

So far I've tried:

open(r'\\.\PartitionLetter:', 'rb')

Without administrative rights, this returns a "Permission denied" error. With administrative rights, this returns a "Parameter is incorrect" error.

open(r'PartitionLetter:', 'rb')

This always returns a "Permission denied" error.

I've tried letters for the OS drive, secondary drive, optical drive and even USB flash drives but always get the same errors.

Is it possible to read a partition with built-ins or are there any good modules/packages that do the job?

uzumaki
  • 1,743
  • 17
  • 32
  • 1
    If you're using 3.5, this should be fixed in 3.5.2. It's trying to stat volume and device files, which isn't supported (either bad function or bad parameter errors). You can work around it by calling `os.open` to get a file descriptor, e.g. `fd = os.open(r'\\.\C:', os.O_BINARY);` `sector_data = os.read(fd, 512)`. – Eryk Sun Feb 28 '16 at 18:39
  • For more details, see [issue 25639](http://bugs.python.org/issue25639). – Eryk Sun Feb 28 '16 at 19:07
  • As a side note: `os.read` only takes multiples of 512 as the second argument. – uzumaki Feb 28 '16 at 19:19
  • Volume access is handled directly by the disk driver, which requires reads to be a multiple of the sector size. Assuming the logical sector size is 512 bytes should usually work. Otherwise query the [`STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR`](https://msdn.microsoft.com/en-us/library/ff800831) for the device. – Eryk Sun Feb 28 '16 at 19:54
  • The [`IOCTL_DISK_GET_DRIVE_GEOMETRY`](https://msdn.microsoft.com/en-us/library/aa365169) control code also gets the `BytesPerSector` in the returned [`DISK_GEOMETRY`](https://msdn.microsoft.com/en-us/library/aa363972). – Eryk Sun Feb 28 '16 at 20:08

0 Answers0