Monday, October 11, 2010

Case Sensitive File System on OSX

I recently had to determine if the file system was case sensitive on OSX. It was actually throw away work but figured I'd post it to my blog in case anyone else out there needed to do the same thing and didn't want to start from scratch.

#include <CoreServices/CoreServices.h>
#include <CoreFoundation/CFString.h>

BOOL IsFileSystemCaseSensitive(const char* path)
  FSRef ref;
  FSCatalogInfo info;
  GetVolParmsInfoBuffer buffer;

  if ((FSPathMakeRef((const UInt8*)path, &ref, NULL) == noErr) &&
      (FSGetCatalogInfo(&ref, kFSCatInfoVolume, &info, NULL, NULL, NULL) == noErr) &&
      (FSGetVolumeParms(info.volume, &buffer, sizeof(buffer)) == noErr) &&
      (buffer.vMVersion > 2))
    if ((buffer.vMExtendedAttributes & (1 << bIsCaseSensitive)) != 0)
      return TRUE;
  return FALSE:

If the path parameter is simply an ANSI string then this function works fine. However, if it is a unicode string, then you'll need to call CFStringGetFileSystemRepresentation to get everything encoded correctly.

No comments:

Post a Comment