如何取得磁碟分割的叢集大小

一般在格式化磁碟(應該說分割區-partition)時, 有個選項可以設定, 就是叢集大小.

但是指定完成後, 要查詢, 卻不是那麼容易. 可以利用 chkdsk 指定來達成 (http://support.microsoft.com/kb/245436/en-us/), 但是總會需要到檢查一段依磁碟大小愈大而愈久的檢查, 有沒有辦法有更直接的方法?

若是在 NTFS 分割區時, 可以利用指令來達成:

fsutil fsinfo ntfsinfo c:

結果如下:

NTFS Volume Serial Number : 0x3accf140ccf0f74b
Version : 3.1
Number Sectors : 0x0000000009c41ad7
Total Clusters : 0x000000000138835a
Free Clusters : 0x0000000000c9dd73
Total Reserved : 0x0000000000000060
Bytes Per Sector : 512
Bytes Per Cluster : 4096
Bytes Per FileRecord Segment : 1024
Clusters Per FileRecord Segment : 0
Mft Valid Data Length : 0x0000000008c64000
Mft Start Lcn : 0x00000000000c0000
Mft2 Start Lcn : 0x00000000009c41ad
Mft Zone Start : 0x0000000000e2a2c0
Mft Zone End : 0x00000000010926e0

但是這個僅適用於 NTFS, 若是 FAT32 的話呢? 再找看看其他的方式, 可以利用 WMI 來達成, 如下: (以下是 VBScript)

strComputer = "."
strDrive = "c:" 

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume Where Name='" & strDrive & "\\'")

For Each objVolume in colVolumes
    errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
    If errResult = 0 then
        Wscript.Echo "Cluster size: " & objReport.ClusterSize
    End If
Next

這個是利用了 WMI , 使用DefragAnalysis 的功能, 來取出磁碟資訊的方式, 其中有 ClusterSize 的屬性(單位是 bytes), 可以做為檢查磁碟 ClusterSize 這個功能. 其中的 strDrive 就是要查詢的磁碟機代碼, 也可以讀取 FAT32 的磁碟分割, 十分方便, 速度也很快.

本文介紹的兩種方式, 可以依實際狀況來使用, 很方便.

參考資料:

微軟KB: http://support.microsoft.com/kb/245436/en-us/

http://www.vistax64.com/powershell/77645-getting-cluster-size-your-hard-disk.html

http://www.activexperts.com/activmonitor/windowsmanagement/scripts/storage/diskdrives/physical/#AVD.htm

http://www.scribd.com/doc/15490968/Windows-Server-Cookbook-by-OReilly-Media (這本書的108頁)

http://msdn.microsoft.com/en-us/library/aa389827%28VS.85%29.aspx