From: Charles S. <bas...@ch...> - 2012-06-24 19:46:15
|
On Jun 24, 2012, at 1:41 PM, Alexei Svitkine wrote: > On Sun, Jun 24, 2012 at 2:31 PM, Robert Munafo <mr...@gm...> wrote: > I like the first idea, because it is careful. > > The second idea will make volumes get locked, and therefore > permanently damaged" (unmountable) the very first time SheepShaver or > BasiliskII crashes. > > I was thinking of the "lock" option that the user can then do a Get Info -> uncheck "Locked" checkbox in Finder in such a scenario. The proper way to do this is to request an exclusive lock when openin the disk image file. This used to be standard practice in ye olde Mac OS (IIRC, pretty much every file open operation resulted in an exclusive lock being automatically granted), but in OS X that behavior changed. You can still ask for exclusive locks if you explicitly ask for them, though. You can do this by passing O_EXLOCK to the open() function. If you want open() to fail immediately if the file is already open instead of simply blocking until the file is available, then pass O_NONBLOCK as well. I just tested this on Snow Leopard and Lion, and it works. When you’ve got a disk image mounted, open(path, O_RDWR | O_EXLOCK | O_NONBLOCK) fails with EAGAIN. If I’ve got a disk image open with O_EXLOCK and then I try to mount it in the Finder, DiskImageMounter fails with “Resource temporarily unavailable”. So this should do what you want without having to monkey with permanent metadata bits on the file. Charles |