Find the answer to your Linux question:
Results 1 to 4 of 4
any expert here know if there is C function call that i can convert major, minor pair to device path? unless no choice, google but only find some code on ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    14

    major/minor number to device path translate


    any expert here know if there is C function call that i can convert major, minor pair to device path?

    unless no choice, google but only find some code on devfs which i am not using.

    think of use a recursive C to call "ls -l" command, then awk out the major, minor, compare, then return dev path string, but seems too clumsy....

    please help..

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    In fact there is no way to map device numbers into a pathname. The pathnames are just instances of a device mapping and there is no backward link. The primitive filesystem structure doesn't allow that.

    I'd that the only way to do that is to use readdir and stat to go through /dev and find the one you want.

    What is it that you want to do, more exactly? There might be a smoother way to accomplish it.

  3. #3
    Just Joined!
    Join Date
    Jan 2004
    Location
    Toronto, Canada
    Posts
    14
    thanks sir. yes, that is what i have done yesterday, use opendir, stat and readdir and build up a recursive algothrim to get the device path based on major:minor id. I had thought kernel would keep such a table there so that i did not have to re-walk through the directory again and again, too bad, i did not find such thing.. :>(

    i was building a program that map the output from Linux RAID (in Major:minor format) to its underlying device.

    you explained the linux disk block to me before for the same project.

    thanks....

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Sorry. The kernel knows nothing at all about device pathnames, since the exist only in userspace. The kernel only identifies devices by their numbers.

    However, if you use Linux 2.6, there is a clean way to find out about device information through sysfs. You still can't find out the actual pathnames in any other way, but it's easy to get a lot of information about the devices through sysfs. sysfs doesn't exist in Linux 2.4 or earlier, though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •