Sponsored Content
Full Discussion: device number registration
Top Forums UNIX for Advanced & Expert Users device number registration Post 302673633 by dr_mabuse on Wednesday 18th of July 2012 07:35:01 AM
Old 07-18-2012
device number registration

I would THANK if you answer my doubts in DETAILS please.

Here's a sample code to create a device:

Code:
if(scull_major) {
  dev=MKDEV(scull_major, scull_minor);
  result=register_chrdev_region(dev, scull_nr_devs, "scull");
} else{
   result=alloc_chrdev_region(&dev, scull_minor, scull_nr_devs,  "scull");
 scull_major=MAJOR(dev);
}

if(result < 0)
{
   printk(KERN_WARNING "scull:can't get major %d\n", scull_major);
   return result;
}

1. I didn't understand the first line! In the second and third lines, a device is created using the given minor and major numbers (I am sure this is a static allocation) and register_chrdev creates multiple instances of it.
what about the first line? I can't understand what that if(major number) doing there, what's so relevant to it?

2. if the major number is not created it goes to while n creates a dynamic major number. Major number means the driver ID to which the device associates with, OK? but so far, how would the kernel know about which driver it shall connect it? it just allocates one dynamically!

3.
Quote:
register_chrdev_region works well if you know ahead of time exactly which device numbers you want. Often, However, you will not know which major numbers your device will use.
!!! what's so relevant between major number and device numbers in 3? major number is the driver number the device associates with and it's not the device number (that's minor number). So, why 3 notes that?

4. Why do we need a seperate script to read /proc/devices file?
 

3 More Discussions You Might Find Interesting

1. Programming

How to check number of first slot on the MO or TAPE device?

Hi, I need to discover is MO or Tape device counting slots begining on 0 or 1. THS (0 Replies)
Discussion started by: HrnjicaMujo
0 Replies

2. Linux

Device serial number

Hey! I'm trying to figure out a sollution for a problem I have at my company with an Iomega MiniMax 500 GB USB disk. If i run cat /proc/bus/usb/devices I get this information: T: Bus=01 Lev=02 Prnt=04 Port=00 Cnt=01 Dev#= 5 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00... (2 Replies)
Discussion started by: noratx
2 Replies

3. Solaris

some questions on the minor number of device

hi, dear all Now I have a problem on the minor number of device. I have many sd disks. The sd driver will create many minor numbers for these disks when attached. But the sd driver may be not remove thest minor number when detached. The minor number will become very big If I attach and... (2 Replies)
Discussion started by: ForgetChen
2 Replies
MAKEDEV(3)						   BSD Library Functions Manual 						MAKEDEV(3)

NAME
makedev, major, minor -- device number conversion SYNOPSIS
#include <sys/types.h> dev_t makedev(int major, int minor); int major(dev_t dev); int minor(dev_t dev); DESCRIPTION
The makedev() macro allows a unique device number to be generated based on its major and minor number. The major() and minor() macros can be used to obtain the original numbers from the device number dev. In previous implementations of FreeBSD all block and character devices were uniquely identified by a pair of major and minor numbers. The major number referred to a certain device class (e.g. disks, TTYs) while the minor number identified an instance within the device class. Later versions of FreeBSD automatically generate a unique device number for each character device visible in /dev/. These numbers are not divided in device classes. On FreeBSD these macros are only used by utilities that need to exchange numbers with other operating systems that may use different encod- ings for dev_t, but also applications that present these numbers to the user in a more conventional way. RETURN VALUES
The major() macro returns a device major number that has a value between 0 and 255. The minor() macro returns a device minor number whose value can span the complete range of an int. SEE ALSO
mknod(2), devname(3), devfs(5) BSD
September 28, 2008 BSD
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy