Solved

Disk Cluster Size

Posted on 2002-03-16
13
1,361 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
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 show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
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…

815 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

15 Experts available now in Live!

Get 1:1 Help Now