title: "fd not available for reading or writing" when memory-mapping a file
body: <p>I am trying to write data to a memory-mapped file in Rust but it won't memory map the specified file as it states the given fd is not available. </p>
  
  <p>I can see it on the filesystem so it does exist with correct privileges. I suspect this is either a bug or I am not using the new IO API in the correct way.</p>
  
  <p><code>mmap err = fd not available for reading or writing</code></p>
  
  <p>Here's the code</p>
  
  <pre><code>use std::fs::File;
  use std::os::MemoryMap;
  use std::os::unix::prelude::AsRawFd;
  use std::os::MapOption::{MapFd, MapWritable, MapReadable};
  
  fn main() {
      let f = File::create("test.dat").unwrap();
      f.set_len(n as u64);
  
      let fd = f.as_raw_fd();
  
      let mmap = MemoryMap::new(n, &amp;[MapReadable, MapWritable, MapFd(fd)]);
  
      match mmap {
          Ok(_) =&gt; println!("mmap success"),
          Err(ref err) =&gt; println!("mmap err = {}", err),
      }
  }
  </code></pre>