Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:26:37+00:00 2026-06-18T08:26:37+00:00

I have a small program which I’m using to attempt to read out the

  • 0

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.

A check of the /dev directory shows 8 mtds all with the same permissions:

# 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

My application is also running as root:

# ls -al mtd_test
-rwxrwxrwx    1 root     root        19688 Nov 30 01:18 mtd_test

Checking the /proc I can see that 7 of the 8 mtd’s are mounted (so I expected mtd7 to fail to be read)

# 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)"

Oddly, only mtd1 and mtd6 were able to be read, all the others failed with an error “Permission denied”, does anyone have any idea why this would be?

I doubt it’s my code, but here it is:

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 < 16; count++) {
        fd = open(devs[count], O_RDWR);
        if(fd > 0) {
            ioctl(fd, MEMGETINFO, &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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:26:38+00:00Added an answer on June 18, 2026 at 8:26 am

    If you are using an ext family FS, the command lsattr works at a deeper level on access rights, but usually doesn’t apply to /dev/* – you can try anyway. The jffs2 FS planned to implement lsattr – not sure if they did.

    The O_RDONLY access instead of O_RDWR could help for reading the memory – some devices require a specific protocol to be written to, while reading may be freely allowed.

    Maybe playing with the man 2 open flags – like O_SYNC etc… – may help.

    There is this page but the author uses O_RDWR as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small program that which is confusing me. I am trying using
I have written a small bash program which needs to read a file with
Problem: Have made a small mail program which works perfectly on my developer pc
I have a small Python OOP program in which 2 class, Flan and Outil
I have a small Python program, which uses a Google Maps API secret key.
I have a small program which compares (1) sizeof, (2) numeric_limits::digits, (3) and the
I have made a program which is a small library operated via software. When
I have a small .NET 3.5 program which raises errors when trying to connect
I have a small program that is mostly using regular set 's but now
I have a small ncurse program I'm running, but the output doesn't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.