0

Mostly as the title says; I would like to add support to my program such that it can detect when a particular volume or device is being unmounted/ejected, so that it can close file-handles for that volume and halt processing, such that the volume/drive can unmount without issues.

Currently I have a very basic database connection, but since it is seen as an open file-handle, it currently prevents the host volume from being unmounted or ejected at all until my program is closed. However, the program is intended to run as a daemon process, so really it needs to be able to close down in such cases.

Although I could try to create a working database elsewhere, there would still be the potential for syncing of changes to interrupt ejection of the disk, so I'd like a way to clean detect and avoid such issues.

David Berry
  • 40,941
  • 12
  • 84
  • 95
Haravikk
  • 3,109
  • 1
  • 33
  • 46
  • 1
    Not sure whether swift/obj-c tags are valid here. It's more about the OS than a specific language. – Sulthan Jan 16 '15 at 16:31
  • As Sulthan said, this is an OS issue more than anything else. Find a way of doing it in C/C++ and you've found a way in Objective-C (and possibly Swift, the mappings aren't 100%) – David Berry Jan 16 '15 at 16:47
  • Maybe this will help: https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/notify_post.3.html – KirkSpaziani Jan 16 '15 at 16:54
  • possible duplicate of [Detect when a volume is mounted on OS X](http://stackoverflow.com/questions/12409458/detect-when-a-volume-is-mounted-on-os-x) – David Berry Jan 16 '15 at 17:00
  • Sorry about that, @David's link isn't an exact duplicate, but it does appear to contain the correct answer. Should this question be closed as a duplicate in that case? – Haravikk Jan 17 '15 at 13:04
  • Generally speaking, yes. Closing duplicates makes it easier to find the source answer. – David Berry Jan 19 '15 at 01:12

0 Answers0