Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

goyalpk

macrumors newbie
Original poster
Aug 7, 2009
14
0
Hi there,
How I can I find out sector size of Hard disk or USB flash drive using Cocoa or OS API?
I wanted to use getPreferredBlockSize() method of IOMedia class, but IOMedia is an abstract class.
It is urgent.
Thanks so much in advance.
Pankaj
 
If you have the /dev/ path to the device, you can use open() to get a file descriptor for it, then ioctl() with DKIOCGETBLOCKSIZE.
 
Thanks a lot for reply. Is there any high level function in Cocoa to do this?
Thanks.
Pankaj
 
Another option you have is to use IOKit to enumerate through the kIOBlockStorageDriverClass instances in the IOService tree and grab the kIOMediaPreferredBlockSizeKey property for the ones you want. IIRC, this is the optimal block size of the device not necessarily the logical block size.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.