title: Can't write raw data on SD card under Linux in C
body: <p>I am trying to write raw data on my SD card under Linux Ubuntu 14.04. </p>
  
  <p>I need this cause I want to write my own "filesystem" from which I can easily read under microcontroller (arm based). </p>
  
  <p>I am able to read data from SD card, but when I try to write some it gives me an error of: </p>
  
  <p>"<code>Operation not permitted</code>".</p>
  
  <p>This is the code I'm using:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;      /* open */
  #include &lt;unistd.h&gt;     /* exit */
  #include &lt;sys/ioctl.h&gt;      /* ioctl */
  #include &lt;errno.h&gt;
  #define DEVICE "/dev/sdb1" /* SD card */
  
  int main()
  {
     int file_desc, ret_val;
     char msg[512];
     msg[0] = 'H';
     char answer[512];
     file_desc = open(DEVICE, O_RDWR);
     if(file_desc &lt; 0)
        printf("failed to open the device \n");
  
     ret_val = write(file_desc, msg, 512);
     fsync(file_desc);
     printf("%d\n", ret_val);
     printf("%d\n", errno);
     read(file_desc, answer, 512);
  
     printf("message read is %s\n", answer);
     close(file_desc);
     return 0;
  }
  </code></pre>
  
  <p>As I said, I can open file in <code>read/write</code> mode and read data from it, but in these lines:</p>
  
  <pre><code>ret_val = write(file_desc, msg, 512);
  fsync(file_desc);
  printf("%d\n", ret_val);
  printf("%d\n", errno);
  </code></pre>
  
  <p>I get <code>ret_val = -1</code> (which means error), and <code>errno = 1</code> (which means " Operation not permitted"). </p>
  
  <p>I would be very grateful for any advice that would help me write raw data on my SD card.</p>