1. How to get the blocksize of a device

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

new topic     » topic index » view message » categorize

2. Re: How to get the blocksize of a device

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 message » categorize

3. Re: How to get the blocksize of a device

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.

If I did understand you correctly, then you are looking for the size of
what I know as "cluster". If so, then you can get the wanted information
from the Windows API function "GetDiskFreeSpace". Under Windows 95/98/Me
there can be problems, though. For details see
<http://msdn2.microsoft.com/en-us/library/aa364935.aspx>

Regards,
   Juergen

new topic     » goto parent     » topic index » view message » categorize

4. Re: How to get the blocksize of a device

* Some * of the wrapping work for GetDiskFreeSpace has been done for you 
already. look here:

http://www.openeuphoria.org/cgi-bin/esearch.exu?thread=1&fromMonth=C&fromYear=6&toMonth=2&toYear=7&keywords="cluster+size"

http://www.rapideuphoria.com/getdrivesinfo.zip

http://www.openeuphoria.org/cgi-bin/esearch.exu?thread=1&fromMonth=3&fromYear=6&toMonth=5&toYear=6&keywords="GetDrives()++and+GetDrivesReady()++wrapped"

Yours, OtterDad

Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford

new topic     » goto parent     » topic index » view message » categorize

5. Re: How to get the blocksize of a device

Thanks for the replies,
Christian Cuvier in particular for the detailed help.
That API approach seems much more than I am likely to get working ;) 
and I want to keep the code in Euphoria anyway.

Well, I will assume a cluster/block will always be a multiple of 512.
Then use tasking and seek()in 512 byte increments to read the faulty file.

Thanks guys,
Regards
Alan

new topic     » goto parent     » topic index » view message » categorize

6. Re: How to get the blocksize of a device

Alan Oxley wrote:
> 
> Thanks for the replies,
> Christian Cuvier in particular for the detailed help.
> That API approach seems much more than I am likely to get working ;) 
> and I want to keep the code in Euphoria anyway.
> 
> Well, I will assume a cluster/block will always be a multiple of 512.
> Then use tasking and seek()in 512 byte increments to read the faulty file.
> 
> Thanks guys,
> Regards
> Alan

Actually, Juergen's solution is better, since it avoids the need for version
dependent function codes.
The # of bytes per sector will be returned correctly under all OSes. However,
other returned values do have issues, and GetDiskFreeSpaceEx() is to be preferred
instead then - but Win95 OSR1 doesn't support it.

Wrapping either of the vanilla or Ex function is done the standard way in
Euphoria, so no need for C header files here.

CChris

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu