title: Risks and rewards of using /dev/autofs_nowait on OS X
body: <p>Throughout the <a href="https://github.com/opensource-apple/CF" rel="nofollow noreferrer">CoreFoundation framework source</a>, POSIX filesystem API calls (e.g. <code>open()</code>, <code>stat()</code>, <em>et al…</em>) are <a href="https://github.com/opensource-apple/CF/blob/3cc41a76b1491f50813e28a4ec09954ffa359e6f/CFFileUtilities.c#L65-L71" rel="nofollow noreferrer">wrapped in an idiom</a> wherein a descriptor on <code>/dev/autofs_nowait</code> is acquired – with <code>open(…, 0)</code> – before the POSIX calls are made; afterwards the descriptor is <code>close()</code>’d before the scope exits.</p>
  
  <ul>
  <li><p>What is the benefit of doing this? What are the risks?</p></li>
  <li><p>Does acquiring the <code>/dev/autofs_nowait</code> descriptor have any affect on, or is it effected by, flags to any thusly-wrapped <code>open()</code> calls (like e.g. <code>O_NONBLOCK</code>)?</p></li>
  <li><p><code>/dev</code> on my machine, running OS X 10.10.5 has other “autofs” entries:</p>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/JSIcG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JSIcG.jpg" alt="dev directory listing"></a></p>
  </blockquote>
  
  <p>… none of which have <code>man</code> pages available. If these file-like devices might offer benefits in this vein I would be interested to hear about their use as well, as it may pertain.</p></li>
  </ul>
  
  <p><br></p>
  
  <hr>
  
  <p>Addendum: I could not find much on this subject; a <a href="https://plus.google.com/106726538507001003804/posts/a83FonJPfYg" rel="nofollow noreferrer">Google Plus post from 2011</a> claims that:</p>
  
  <blockquote>
    <p>[t]his file is a special device that's monitored by the autofs
    filesystem implementation in the kernel. When opened, the autofs
    filesystem will not block that process on any I/O operations on an
    autofs file system.</p>
  </blockquote>
  
  <p>I am not quite sure what that means (they were specifically talking about how <code>launchd</code> works, FWIW) but I was curious about this myself, so I wrote <a href="https://github.com/fish2000/libimread/blob/master/include/libimread/ext/filesystem/nowait.h" rel="nofollow noreferrer">a quick  context-manager-y RAII struct</a> to <a href="https://github.com/fish2000/libimread/blob/7a8b832a690406ac5a1c3eaca00cef71f0a2b4fe/src/ext/filesystem/path.cpp#L862-L896" rel="nofollow noreferrer">try it out</a> – untargeted profiling shows  tests with POSIX calls completing faster but within general hashmarks; I’ll investigate this tactic with a finer-toothed comb after I get more background on how it all works.</p>