Solved

Disk Cluster Size

Posted on 2002-03-16
13
1,368 Views
Last Modified: 2013-12-04
Simple: How do I get the disk cluster size of a partition using WMI (Windows Management Instrumentation)? This is since I'm developing in C# and can't use DeviceIoControl.
0
Comment
Question by:Owlguru
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 300 total points
ID: 6873473
Specifics on default cluster sizes are listed here:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q140365


Short of using DeviceIoControl() or reading the MBR off the disk, the only way I can think of to determine cluster size is by experimentation, to wit, get available space, create a 1k file, check available space again, delete the 1k file, then create a 2k file and check available space again.  

Once you get a change in avaiable space you know you found the cluster size.

Another possibility would be to shell out to a chkdsk and parse the output.  Alas, I can't tell you if the format of the output varies among the various flavors of Windows.

Under 2k, the target line looks like:

x bytes in each allocation unit

0
 

Author Comment

by:Owlguru
ID: 6875257
cookre, I never thought of doing it by experimentation. I'm gonna try to try that :-). But what do I do for CD-ROMs and read-only disks?
0
 
LVL 22

Expert Comment

by:cookre
ID: 6875309
Chances are, the only non-default cluster sizes you'll ever find areon hard drives on custom built boxes.  Note that includes custom configured commercial boxes.

Experimentation can also be done without writing files.  Count the number of files in various size categories (0-512, 513-1k, 1k+1-2k, 2k+1-4k,...), posit a cluster size, then see if the results jibe with reported space available.  If they don't, try a different size.  Unless a device has a weird cluster size, you'll hit on the right one eventually.

Specifically, cou

My preference would be chkdsk, assuming it's available and gives cluster size under your target OS's.  Any variations in OS specific output formatting can be dealt with easily.  Granted, though, it's not a very sexy solution.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 22

Expert Comment

by:cookre
ID: 6875312
Ignore the 'Specifically, cou'.

Damned bifocals.
0
 

Author Comment

by:Owlguru
ID: 6875375
Isn't CHKDSK kinda slow? (It takes a while to finish checking the disk) Also, on Windows 2000 or XP, CHKDSK didn't display the cluster size. I like the experimentation method, so I'm gonna use that. I haven't had time to test it yet.

Thanks for everything
0
 
LVL 22

Expert Comment

by:cookre
ID: 6875767
Yeah, it's slow.  BTW, I have it on 2k and xp.

Time for a duh moment.  Wouldn't just creating a 1 byte file reduce the avaiable space by one allocation unit? Duh.
0
 

Author Comment

by:Owlguru
ID: 6875822
Well, I tried that. Doesn't work. The free space stays the same, causing the app to report a 0 KB cluster size.
0
 

Author Comment

by:Owlguru
ID: 6875832
I think it might be because of WMI not updating the information, but even in drive properties, it doesn't change the free space. Weird.. I think the file is simply stored in the MFT (on the NTFS volume), because it's small enough. I heard somewhere, files under 512 bytes can be stored in the MFT.
0
 

Author Comment

by:Owlguru
ID: 6875846
Never mind it works now. I created a 256.1 KB file, then subtracted the new free space from the old free space and then subtracted a further 256 KB. Is that OK or will I run into trouble on drives with 256 KB cluster sizes? (though I doubt there are any)
0
 

Author Comment

by:Owlguru
ID: 6875905
Never mind it works now. I created a 256.1 KB file, then subtracted the new free space from the old free space and then subtracted a further 256 KB. Is that OK or will I run into trouble on drives with 256 KB cluster sizes? (though I doubt there are any)
0
 

Author Comment

by:Owlguru
ID: 6875907
sorry.. seems refreshing the browser posts a comment again :s
0
 

Author Comment

by:Owlguru
ID: 6875908
anyway I'm gonna grant you the 300 points since you gave me the idea of experimenting.
0
 
LVL 22

Expert Comment

by:cookre
ID: 6875917
Well, if you come across an NT4.0 box with an 8-16gig drive with a 16-bit FAT and sector size above 512, you'll get a 256k cluster.

Sounds like a safe bet.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question