1

I'm trying to get the physical location of a file on the disk. This is the current code:

import win32file
import winioctlcon

handle = win32file.CreateFile(raw_input("File: "), win32file.GENERIC_READ, win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE, None, win32file.OPEN_EXISTING, win32file.FILE_ATTRIBUTE_NORMAL | win32file.FILE_FLAG_OVERLAPPED,None)
loc = win32file.DeviceIoControl(handle, winioctlcon.FSCTL_GET_RETRIEVAL_POINTERS,"",8192,None)

When I try to run the code, I get this error:

pywintypes.error: (87, 'DeviceIoControl', '\xfe\xfe\xe4\xf4\xf8\xee\xe8\xf8 \xf9
\xe2\xe5\xe9.')

This error is "Invalid Parameters". What parameters did I use wrong?

Amit Ron
  • 41
  • 1
  • 5
  • of course invalid parameter because you call `DeviceIoControl` absolute incorrect . less parameters than must be. where is `STARTING_VCN_INPUT_BUFFER` ? where is `RETRIEVAL_POINTERS_BUFFER` ? – RbMm Mar 22 '17 at 13:19
  • How do I get these parameters' values? – Amit Ron Mar 22 '17 at 13:24

1 Answers1

0

Please take a look at this MSDN site.

Your count of parameters is incorrect. You need an input buffer and an output buffer. Input is the start VCN (>=0), handle need to be a alternate stream, file, volume or directory handle. Input buffer is of type

typedef struct {
  LARGE_INTEGER StartingVcn;
} STARTING_VCN_INPUT_BUFFER, *PSTARTING_VCN_INPUT_BUFFER;
bkausbk
  • 2,740
  • 1
  • 36
  • 52
  • really `StartingVcn >= 0` (not `>0` ) and file can not be *volume* handle. only alternate stream, file, or directory – RbMm Mar 22 '17 at 13:50
  • You are correct VCN >= 0. Handle can be a volume handle see documentation "This parameter can optionally be a handle to an NTFS volume." – bkausbk Mar 22 '17 at 15:07