The major nuber is the driver associated with the device, while the minor number is used by the kernel to determine which device is being referrd to. You can use the minor number as an index into a local array of devices.
Use dev_t type to hold device number with the help of MACROS defined in <linux/kdev_t.h>. You can obtain major or minor numbers with the following codes:
MAJOR(dev_t dev); MINOR(dev_t dev);
Instead, use the following codes to make a dev_t:
MKDEV(int major, int minor);
Before setting up a char device, your driver need to obtain a device number to work with using register_chrdev_region declared in <linux/fs.h>:
int register_chrdev_region(dev_t first, unsigned int coung, char *name);
"Here, first is the beginning device number of the range you would like to allocate.The minor number portion of first is often 0, but there is no requirement to that effect. count is the total number of contiguous device numbers you are requesting.Note that, if count is large, the range you request could spill over to the next major number; but everything will still work properly as long as the number range your equest is available. Finally, name is the name of the device that should be associatedwith this number range; it will appear in /proc/devices and sysfs."
However, if you have no idea about which number you want, use alloc_chrdev_region to gain a device number:
int alloc_chrdev_region(dev_t *dev, unsigned in firstminor, unsigned int count, char *name);
If successfully completed, dev, as an output-only para, will hold the first number in the allocated range. firstminor should be the requested first minor number to use, always 0.
When device numbers are no longer used, remember to free them with:
void unregister_chrdev_region(dev_t first, unsigned int count);