Solved

Disk Cluster Size

Posted on 2002-03-16
13
1,358 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now