title: What happens internally when a file path exceeds approx. 32767 characters in Windows?
body: <p>In Windows (assume 2000 onwards), a file path can be at most approximately 32767 characters in length. This limitation exists due to the internal handling with <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff564879.aspx"><code>UNICODE_STRING</code></a> in the native API (also on the kernel side, in drivers etc). So far so good. I know the theory behind that part.</p>
  
  <p>The reason for the limit is that the the <code>Length</code> and <code>MaximumLength</code> members of <code>UNICODE_STRING</code> count the number of bytes in the <code>Buffer</code>, but are 16 bit unsigned integers themselves.</p>
  
  <p>I also know why the limit is an approximation rather than a set limit. This is mostly due to how your file name (e.g. <code>\\.\C:\boot.ini</code>) gets resolved to its native form (e.g. <code>\??\C:\boot.ini</code>) and then to something that is prefixed by the <em>actual</em> volume device name and then followed by the path relative to that volume, e.g. <code>\Device\HarddiskVolume2\boot.ini</code>.</p>
  
  <p>Furthermore from Windows Explorer the known symptom when hitting the ("ANSI") <code>MAX_PATH</code> limit is to pretend the file or folder doesn't exist in some versions of Windows (possible this got fixed at some point).</p>
  
  <p><strong>But what happens at the object manager, I/O manager and file system driver levels respectively</strong> when I call <code>CreateFile()</code> with a path that looks like <code>\\.\C:\...\filename.ext</code> and the whole path does <em>not</em> exceed the limit, but <em>reaches</em> it, in my call to <code>kernel32.dll</code>'s <code>CreateFile()</code> and <em>then</em> gets expanded? ...</p>
  
  <p>Neither the SDKs nor the WDKs seem to be particularly chatty about the topic. Or did I look in the wrong sections?</p>