Traversing /dev
hi
I am new to the Linux platfom How can I write a C program to traverse the /dev and print the major and minor numbers of devices. Plz help |
I assume you already know how to use terminal (probably in a terminal emulator inside graphical environment). I also assume you have C programming experience. For many things in Linux you can get documentation using "man" command. So run the following commands:
Code:
man 3 opendir After you have read the documentation, you can ask more specific questions. |
Thanks alot!!
It was of great help. I have another query, I want to use the functions, major (st_rdev) and minor (st_rdev) to get the major and minor numbers resp from the stat structure. But I'm unable to locate the header file that should be included for these functions. |
I am using 'opendir' and 'readdir' functions to traverse the /dev directory. I am also populating the 'stat' structure for each file inside the directory. 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.
I am not too sure abt major(st_rdev) and minor(st_rev) usage. Plz help! |
You are right about major() and minor().
Look at the "man 2 stat" closer. See the "major (3)" reference? This means it is a type-three entity (section three is system library entries). When you see "[name] ([number])" reference in man, you are supposed to look up "man [number] [name]" once you need details. If "man 3 major" leaves some questions unanswered, you are welcome to ask them, of course. |
I am able to use the major(st_rev) and minor(st_rdev) functions and the header file <sys/types.h> for the same.
|
All times are GMT -5. The time now is 09:31 AM. |