title: ioctl and hdreg to get information on harddrives
body: <p>I want to get basic information from a hard-drive and print it out. The most important is that the physical sector size is correct. </p>
  
  <p>For the past few hours I have been fighting with <code>ioctl</code> to get what I want but I can't figure it out.</p>
  
  <p>I have never used <code>ioctl</code> before and I can't seem to find an easy explanation on what exactly you have to do.</p>
  
  <p>Anyway my code looks something like this</p>
  
  <pre><code>int main () {
      FILE *driveptr;
      int sectorsize;
      struct hd_driveid hd;
  
      driveptr=fopen("/dev/sda","r");
  
      if (ioctl(driveptr,HDIO_GET_IDENTITY, &amp;hd)!=0) { 
          printf("Hard disk model: %s\n",hd.model); 
          printf("Serial number: %s\n",hd.serial_no); 
          printf("Sector size: %i\n",hd.sector_bytes);
          sectorsize=hd.sector_bytes;
      } else { 
          printf("Error fetching device data.\n");
      }
  }
  </code></pre>
  
  <p>In the compiler it throws these warnings, it compiles but the strings are empty when printed.</p>
  
  <pre><code>gcc -o test source.c
  source.c: In function ‘main’:
  source.c:67:9: warning: passing argument 1 of ‘ioctl’ makes integer from pointer without a cast [enabled by default]
  /usr/include/x86_64-linux-gnu/sys/ioctl.h:42:12: note: expected ‘int’ but argument is of type ‘struct FILE *’
  </code></pre>
  
  <p>I hope somebody can explain to me what goes wrong!</p>