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

  • SEARCH
  • Home
  • 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 7548791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:47:18+00:00 2026-05-30T09:47:18+00:00

You can specify an MTD device by name on the kernel command line root=mtd:name

  • 0

You can specify an MTD device by name on the kernel command line root=mtd:name and you can mount with a name mount mtd:name. I want my app to be able to do the same thing. It has to call open, but open("mtd:name", ...) fails with No such file or directory.

How do you get from ‘mtd:name’ to ‘/dev/mtd#’?

Updated

This is the code I came up with in case it’s useful to someone else.

int mtd_lookup_minor(const char * mtdname)
{
    int minor;
    unsigned int size, erasesize;
    char name[65];
    char line[128];

    if (mtdname == NULL)
    {
        errno = EINVAL;
        return -1;
    }

    FILE * fp = fopen("/proc/mtd", "r");
    if (fp == NULL)
        return -1;

    while (fgets(line, sizeof(line), fp))
    {
        if (sscanf(line, "mtd%d: %x %x \"%64[^\"]\"", &minor, &size, &erasesize, name) == 4 && strcmp(name, mtdname) == 0)
        {
            fclose(fp);
            return minor;
        }
    }

    fclose(fp);
    errno = ENODEV;
    return -1;
}

/*
 * mtd_open_char allows specifying "mtd:name" instead of /dev/mtd#
 *  to refer to the MTD char device by name.
 */
int mtd_open_char(const char * mtdpath, int oflag)
{
    int minor;
    char pathbuffer[16];

    if (mtdpath == NULL)
    {
        errno = EINVAL;
        return -1;
    }

    if (strlen(mtdpath) > 4 && strncmp(mtdpath, "mtd:", 4) == 0)
    {
        minor = mtd_lookup_minor(mtdpath + 4);
        if (minor < 0 || minor > 9999999) // paranoia fit into pathbuffer
        {
            errno = ENODEV;
            return -1;
        }

        sprintf(pathbuffer, "/dev/mtd%d", minor);
        mtdpath = pathbuffer;
    }

    return open(mtdpath, oflag);
}
  • 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-05-30T09:47:19+00:00Added an answer on May 30, 2026 at 9:47 am

    You can look up MTD names and devices in /proc/mtd.

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

Sidebar

Related Questions

How do I can specify relative path for command-line parameter extra of GWT compiler
I know I can specify one for each form, or for the root form
How can specify expression in LIKE operator I want to select all row in
I need help on how i can specify an array name or key using
In ruby on rails we can specify many Database relations line belongs_to, has_many, and
You can specify in your maven settings file that you want to run in
With CreateFont one can specify font name and a bunch of other properties. However,
The mac command say can specify the voice used with the -v flag. say
I'm creating a web app where users can specify a time and date to
In Subversion you can specify a range of versions to get an aggregate view

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.