Are you working in kernel space (i.e. writing a kernel module) or user space (a regular program)?
You can get a list of device nodes with major and minor versions easily enough:
Code:
find /dev -type b -exec ls -l {} \; ; find /dev -type c -exec ls -l {} \;
. You should be able to parse that to find both the minor numbers and the corresponding device nodes.
If you know that your device is a block device, you can ignore everything from the second semicolon afterwards, and if it's a character device then you can ignore from the start to the second semicolon.
Hope that helps,
—Robert J Lee