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
Solved

Disk Cluster Size

Posted on 2002-03-16
13
1,362 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

829 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