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 ...
- 10-30-2009 #1Just 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
- 10-30-2009 #2
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.
- 10-30-2009 #3Just 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.
- 10-30-2009 #4
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.
- 10-30-2009 #5Just 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!
- 11-02-2009 #6Just 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>


Reply With Quote