How to find out sector size of HD or USB flash drive

Discussion in 'Mac Programming' started by goyalpk, Aug 7, 2009.

  1. goyalpk macrumors newbie

    Aug 7, 2009
    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.
  2. kainjow Moderator emeritus


    Jun 15, 2000
    If you have the /dev/ path to the device, you can use open() to get a file descriptor for it, then ioctl() with DKIOCGETBLOCKSIZE.
  3. goyalpk thread starter macrumors newbie

    Aug 7, 2009
    Thanks a lot for reply. Is there any high level function in Cocoa to do this?
  4. Guiyon macrumors 6502a

    Mar 19, 2008
    North Shore, MA
    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.

Share This Page