title: Open Raw Disk and Get Size OS X
body: <p>Using the following code, I'm able to successfully open a raw disk on my machine, but when I get the disk length I get 0 each time...</p>
  
  <pre><code>// Where "Path" is /dev/rdisk1 -- is rdisk1 versus disk1 the proper way to open a raw disk?
  Device = open(Path, O_RDWR);
  if (Device == -1)
  {
      throw xException("Error opening device");
  }
  </code></pre>
  
  <p>And getting size with both of these methods returns 0:</p>
  
  <pre><code>struct stat st;
  
  if (stat(Path, &amp;st) == 0)
      _Length = st.st_size;
  </code></pre>
  
  <p>/</p>
  
  <pre><code>_Length = (INT64)lseek(Device, 0, SEEK_END);
          lseek(Device, 0, SEEK_SET);
  </code></pre>
  
  <p>I'm not totally familiar with programming on non-Windows platforms, so please forgive anything that seems odd.  My questions here are:</p>
  
  <ol>
  <li>Is this the proper way to open a raw disk under OS X?</li>
  <li>What might be causing the disk size to be returned as 0?</li>
  </ol>
  
  <p>The disk in question is an unformatted disk, but for those wanting the info from Disk Utility (with non-important stuff removed):</p>
  
  <pre><code>Name :  ST920217 AS Media
  Type :  Disk
  
  Partition Map Scheme :  Unformatted
  Disk Identifier      :  disk1
  Media Name           :  ST920217 AS Media
  Media Type           :  Generic
  Writable             :  Yes
  Total Capacity       :  20 GB (20,003,880,960 Bytes)
  Disk Number          :  1
  Partition Number     :  0
  </code></pre>