Re: How to get the blocksize of a device

new topic     » goto parent     » topic index » view thread      » older message » newer message

Alan Oxley wrote:
> 
> Hi!
> I want to write a program where I will copy a file, and skip bad blocks.
> Bad blocks as in hardware error, where windows just gets stuck.
> The base unit of storage on a disk/cd etc is a block. 
> How can I find out what that blocksize is? Similar to Linux's inode size
> for ext2 and ext3 filesystems. On Windows NTFS the blocksize can be
> 512 to 8192 or more? Looking in the archive, the closest I found was a 
> dll called getVolumeInformationA (used by William Heimbigner)
> which gives lots of details but I don't see blocksize.
> Any hints would be appreciated.
> 
> Regards
> Alan

Short answer: get the SDK and do it in C. That's the easiest too.

Otherwise, you have to do this:
* wrap the CreateFile(), CloseHandle() and DeviceIoControl() APIs;
* get a handle to the driver for the disk you have to query, using CreateFile().
You must use a name in the form "DSK%d:", where %d is the number of the physical
drive to query (C: is expected to be drive #1);
* Call DeviceIoControl() using this handle, the IOCTL_DISK_GETINFO action
identifier, and a 24 byte buffer to retrieve disk information, as well as an
unused dword pointer;
* The buffer, if DeviceIoControl() returns TRUE, is filled with a DISK_INFO
structure, the block size is in the dword at offset 8;
* Handles are refcounted, so you must CloseHandle() the handle you just used.
Don't forget freeing the DISK_INFO and dword buffers.

Problem is, I couldn't google for the numerical value of IOCTL_DISK_GETINFO. It
is synthetised by a macro called CTL_CODE which I believe to be version
dependent. That's why it is easier in C - otherwise Eu can handle all of the
above.

All extra info regarding the APIs above can be found on MSDN.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu