What I actually was trying to achieve is to find out when a drive which I had mounted from network is disconnected. For which I started with a very simple approach, I used:
boost::filesystem::exists
on the mounted path of the drive ( which we can find in /Volumes/ ). e.g. for a drive on computer: smb://XYZ/drive after mounting, i can see it like: /Volumes/drive and the later was the drive on which I was using boost::filesystem::exists,
So I was hoping as soon as I will disconnect the network, the mounted volume inside /Volumes will be cleared immediately and everything will work simply.
BUT, later I realize that on network disconnection OSX takes like forever to clear drive from /Volumes directory.
Is there an apple API which can tell whether the amounted volume, which appears in /Volumes is a valid one or not.
Thanks in advance.
There is a method on NSFileManager
that lets you easily look at mounted volumes:
- (NSArray*) mountedVolumeURLsIncludingResourceValuesForKeys:option
- Returns an array of URLs that identify the mounted volumes available on the computer.
I don't know how this deals with stalled mounts though. You will also need to find out if these mounted volumes are network volumes or disk images.
If you want notifications when volumes come and go, you can use the File System Events API. It is a bit more low level but you can basically ask it to 'notify me when the structure under /Volumes/*
changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With