title: What prevents mtd from being read?
body: <p>I have a small program which I'm using to attempt to read out the details of the MTDs on my embedded Linux platform. I'm running into problems where most blocks can't be read and I'm not 100% sure why this is happening.</p>
  
  <p>A check of the <code>/dev</code> directory shows 8 <code>mtd</code>s all with the same permissions:</p>
  
  <pre><code># ls -al | grep "mtd*"
  crwxrwxrwx    1 root     root      90,   0 Jan  1  1970 mtd0
  crwxrwxrwx    1 root     root      90,   2 Jan  1  1970 mtd1
  crwxrwxrwx    1 root     root      90,   4 Jan  1  1970 mtd2
  ...
  crwxrwxrwx    1 root     root      90,  14 Jan  1  1970 mtd7
  </code></pre>
  
  <p>My application is also running as root:</p>
  
  <pre><code># ls -al mtd_test
  -rwxrwxrwx    1 root     root        19688 Nov 30 01:18 mtd_test
  </code></pre>
  
  <p>Checking the <code>/proc</code> I can see that 7 of the 8 mtd's are mounted (so I expected <code>mtd7</code> to fail to be read)</p>
  
  <pre><code># cat /proc/mtd
  dev:    size   erasesize  name
  mtd0: 00020000 00020000 "u-boot (128 kB)"
  mtd1: 00020000 00020000 "u-boot Environment (128 kB)"
  mtd2: 00040000 00020000 "Reserved (256 kB)"
  mtd3: 00200000 00020000 "Kernel (2048 kB)"
  mtd4: 00000064 00020000 "rootFS header"
  mtd5: 003fff9c 00020000 "rootFS (4096 kB)"
  mtd6: 00180000 00020000 "Permanent Storage (1536 KB)"
  </code></pre>
  
  <p>Oddly, only <code>mtd1</code> and <code>mtd6</code> were able to be read, all the others failed with an error "Permission denied", does anyone have any idea why this would be?</p>
  
  <p>I doubt it's my code, but here it is:</p>
  
  <pre><code>int main()
  {
      mtd_info_t mtd_info;
      int count, fd;
      char devs[][15] = { {"/dev/mtd0"},{"/dev/mtdblock0"},
                          {"/dev/mtd1"},{"/dev/mtdblock1"}, 
                          {"/dev/mtd2"},{"/dev/mtdblock2"}, 
                          {"/dev/mtd3"},{"/dev/mtdblock3"}, 
                          {"/dev/mtd4"},{"/dev/mtdblock4"}, 
                          {"/dev/mtd5"},{"/dev/mtdblock5"},
                          {"/dev/mtd6"},{"/dev/mtdblock6"}, 
                          {"/dev/mtd7"},{"/dev/mtdblock7"}, };  
      for(count = 0; count &lt; 16; count++) {
          fd = open(devs[count], O_RDWR);
          if(fd &gt; 0) {
              ioctl(fd, MEMGETINFO, &amp;mtd_info);
              printf("For dev: %s\nMTD Type: %u\nMTD total size: %u bytes\nMTD erase size: %u bytes\n",
              devs[count], mtd_info.type, mtd_info.size, mtd_info.erasesize);
              close(fd);
          }
          else
            printf("Failed for %s: error - %s\n", devs[count], strerror(errno));
      }
      return 0;
  }
  </code></pre>