Berger, Daniel
2008-May-06 21:05 UTC
[Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem
Hi all,
Ok, what am I doing wrong here?
require ''windows/device_io''
require ''windows/handle''
require ''windows/error''
include Windows::DeviceIO
include Windows::Handle
include Windows::Error
fh = File.open(''test.txt'') # Assume you have this
handle = get_osfhandle(fh.fileno)
if handle == INVALID_HANDLE_VALUE
puts "get_osfhandle failed"
fh.close
exit
end
buf = 0.chr * 24 # sizeof(DISK_GEOMETRY)
bytes = [0].pack(''L'')
bool = DeviceIoControl(
handle,
IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752
nil,
0,
buf,
buf.size,
bytes,
0
)
# Fails here
unless bool
puts "DeviceIoControl failed: " + get_last_error
fh.close
exit
End
fh.close
Thanks,
Dan
PS - I''ve added several IOCTL macro methods to Windows::DeviceIO in CVS
(part of windows-pr).
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.
Heesob Park
2008-May-07 01:38 UTC
[Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem
Hi, 2008/5/7 Berger, Daniel <Daniel.Berger at qwest.com>:> Hi all, > > Ok, what am I doing wrong here? > > require ''windows/device_io'' > require ''windows/handle'' > require ''windows/error'' > include Windows::DeviceIO > include Windows::Handle > include Windows::Error > > fh = File.open(''test.txt'') # Assume you have this > > handle = get_osfhandle(fh.fileno) > > if handle == INVALID_HANDLE_VALUE > puts "get_osfhandle failed" > fh.close > exit > end > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > bytes = [0].pack(''L'') > > bool = DeviceIoControl( > handle, > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > nil, > 0, > buf, > buf.size, > bytes, > 0 > ) > > # Fails here > unless bool > puts "DeviceIoControl failed: " + get_last_error > fh.close > exit > End > > fh.close > > Thanks, > > Dan > > PS - I''ve added several IOCTL macro methods to Windows::DeviceIO in CVS > (part of windows-pr). > >What do you want to do? DeviceIoControl works not with file handle but with device handle. Here is a working code: require ''windows/file'' require ''windows/device_io'' require ''windows/handle'' require ''windows/error'' include Windows::File include Windows::DeviceIO include Windows::Handle include Windows::Error buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) bytes = [0].pack(''L'') handle = CreateFile("\\\\.\\c:",0,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0) bool = DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 nil, 0, buf, buf.size, bytes, 0 ) unless bool puts "DeviceIoControl failed: " + get_last_error fh.close exit end Regards, Park Heesob
Daniel Berger
2008-May-07 01:45 UTC
[Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem
On Tue, May 6, 2008 at 7:38 PM, Heesob Park <phasis at gmail.com> wrote:> Hi, > > 2008/5/7 Berger, Daniel <Daniel.Berger at qwest.com>: > > > > Hi all, > > > > Ok, what am I doing wrong here? > > > > require ''windows/device_io'' > > require ''windows/handle'' > > require ''windows/error'' > > include Windows::DeviceIO > > include Windows::Handle > > include Windows::Error > > > > fh = File.open(''test.txt'') # Assume you have this > > > > handle = get_osfhandle(fh.fileno) > > > > if handle == INVALID_HANDLE_VALUE > > puts "get_osfhandle failed" > > fh.close > > exit > > end > > > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > > bytes = [0].pack(''L'') > > > > bool = DeviceIoControl( > > handle, > > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > > nil, > > 0, > > buf, > > buf.size, > > bytes, > > 0 > > ) > > > > # Fails here > > unless bool > > puts "DeviceIoControl failed: " + get_last_error > > fh.close > > exit > > End > > > > fh.close > > > > Thanks, > > > > Dan > > > > PS - I''ve added several IOCTL macro methods to Windows::DeviceIO in CVS > > (part of windows-pr). > > > > > What do you want to do? > DeviceIoControl works not with file handle but with device handle.<snip> Hm, is there any way to go from file handle to device handle? Thanks, Dan
Heesob Park
2008-May-07 06:32 UTC
[Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem
2008/5/7 Daniel Berger <djberg96 at gmail.com>:> > On Tue, May 6, 2008 at 7:38 PM, Heesob Park <phasis at gmail.com> wrote: > > Hi, > > > > 2008/5/7 Berger, Daniel <Daniel.Berger at qwest.com>: > > > > > > > Hi all, > > > > > > Ok, what am I doing wrong here? > > > > > > require ''windows/device_io'' > > > require ''windows/handle'' > > > require ''windows/error'' > > > include Windows::DeviceIO > > > include Windows::Handle > > > include Windows::Error > > > > > > fh = File.open(''test.txt'') # Assume you have this > > > > > > handle = get_osfhandle(fh.fileno) > > > > > > if handle == INVALID_HANDLE_VALUE > > > puts "get_osfhandle failed" > > > fh.close > > > exit > > > end > > > > > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > > > bytes = [0].pack(''L'') > > > > > > bool = DeviceIoControl( > > > handle, > > > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > > > nil, > > > 0, > > > buf, > > > buf.size, > > > bytes, > > > 0 > > > ) > > > > > > # Fails here > > > unless bool > > > puts "DeviceIoControl failed: " + get_last_error > > > fh.close > > > exit > > > End > > > > > > fh.close > > > > > > Thanks, > > > > > > Dan > > > > > > PS - I''ve added several IOCTL macro methods to Windows::DeviceIO in CVS > > > (part of windows-pr). > > > > > > > > What do you want to do? > > DeviceIoControl works not with file handle but with device handle. > > <snip> > > Hm, is there any way to go from file handle to device handle? >It is possible but not easy. Refer to http://msdn.microsoft.com/en-us/library/aa366789.aspx Regards, Park Heesob
Daniel Berger
2008-May-07 12:06 UTC
[Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem
On Wed, May 7, 2008 at 12:32 AM, Heesob Park <phasis at gmail.com> wrote:> 2008/5/7 Daniel Berger <djberg96 at gmail.com>: > > > > > > On Tue, May 6, 2008 at 7:38 PM, Heesob Park <phasis at gmail.com> wrote: > > > Hi, > > > > > > 2008/5/7 Berger, Daniel <Daniel.Berger at qwest.com>: > > > > > > > > > > Hi all, > > > > > > > > Ok, what am I doing wrong here? > > > > > > > > require ''windows/device_io'' > > > > require ''windows/handle'' > > > > require ''windows/error'' > > > > include Windows::DeviceIO > > > > include Windows::Handle > > > > include Windows::Error > > > > > > > > fh = File.open(''test.txt'') # Assume you have this > > > > > > > > handle = get_osfhandle(fh.fileno) > > > > > > > > if handle == INVALID_HANDLE_VALUE > > > > puts "get_osfhandle failed" > > > > fh.close > > > > exit > > > > end > > > > > > > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > > > > bytes = [0].pack(''L'') > > > > > > > > bool = DeviceIoControl( > > > > handle, > > > > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > > > > nil, > > > > 0, > > > > buf, > > > > buf.size, > > > > bytes, > > > > 0 > > > > ) > > > > > > > > # Fails here > > > > unless bool > > > > puts "DeviceIoControl failed: " + get_last_error > > > > fh.close > > > > exit > > > > End > > > > > > > > fh.close > > > > > > > > Thanks, > > > > > > > > Dan > > > > > > > > PS - I''ve added several IOCTL macro methods to Windows::DeviceIO in CVS > > > > (part of windows-pr). > > > > > > > > > > > What do you want to do? > > > DeviceIoControl works not with file handle but with device handle. > > > > <snip> > > > > Hm, is there any way to go from file handle to device handle? > > > It is possible but not easy. > Refer to http://msdn.microsoft.com/en-us/library/aa366789.aspxYes, I saw that. I was hoping to avoid it. I thought maybe there was an easier way somewhere. Thanks, Dan