Find the answer to your Linux question:
Results 1 to 6 of 6
Hi I am new to the Linux platform. How can I write a C program to traverse the /dev and print the major and minor numbers for the devices Plz ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10

    traverse /dev

    Hi

    I am new to the Linux platform.

    How can I write a C program to traverse the /dev and print the major and minor numbers for the devices

    Plz help

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    The easy way is to invoke "ls -l" on /dev and parse the output you get back.

    There surely is also a way to do it all by hand, maybe with the st_rdev variable from a stat call. Or maybe with readdir. But I don't know how to do that now.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10
    Thanks Alot!!

    that was of great help.

    I wish to use the functions major (st_rdev) and minor (st_rdev) to retrieve the major and minor numbers from the stat structure.
    But I'm unable to locate the header file that needs to be included for these functions.

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Are major and minor really functions?
    On a swift look, it seems they just refer to the higher/lower 8bits of a 16bit word.
    Debian GNU/Linux -- You know you want it.

  5. #5
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10
    I'm not sure.

    I am using 'opendir' and 'readdir' functions to traverse the /dev directory. I am also populating the 'stat' structure for each file. But the structure doesnt have a direct entry for major and minor numbers. Is there a way to retrieve this information, from the already available information in the 'stat' struct.

    Plz help!

  6. #6
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10
    I am able to retirieve the major and minor numbers using major(st_rdev) and minor(st_rdev) functions and the header file is <sys/types.h>

Posting Permissions

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