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

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

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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

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

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #4
    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