The problem with checking for paths in /Volumes is that it also includes internal partitions, like /Volumes/WINDOWS. Also, although rare, external drives can have mount points other than /Volumes
The more correct way is to use FSGetVolumeParms()
to get a GetVolParmsInfoBuffer
structure that contains information about the volume, like bIsEjectable
, bIsRemovable
, bIsOnInternalBus
.
You can get the FSVolumeRefNum from a FSRef using FSGetCatalogInfo()
:
FSCatalogInfo info = {0};
OSErr status = FSGetCatalogInfo(&fsRef, kFSCatInfoVolume, &info, nil, nil, nil);
if (status == noErr)
{
_volumeRefNum = info.volume;
}
With the volumeRef, you can get the volume params:
FSGetVolumeParms(_volumeRefNum, &_params, sizeof(_params));
_params is a GetVolParmsInfoBuffer
structure that has info such as:
- (BOOL) isEjectable
{
return (_params.vMExtendedAttributes & (1 << bIsEjectable)) != 0;
}
- (BOOL) isRemovable
{
return (_params.vMExtendedAttributes & (1 << bIsRemovable)) != 0;
}
- (BOOL) isAutoMounted
{
return (_params.vMExtendedAttributes & (1 << bIsAutoMounted)) != 0;
}
- (BOOL) isExternal
{
return (_params.vMExtendedAttributes & (1 << bIsOnExternalBus)) != 0;
}
- (BOOL) isInternal
{
return (_params.vMExtendedAttributes & (1 << bIsOnInternalBus)) != 0;
}